-
Install Docker
brew install --cask docker-edge
-
Check if the Docker is up and running
$ docker --version Docker version 20.10.0-rc2, build dca98e3
-
Pull the Elasticsearch Docker image
$ docker pull docker.elastic.co/elasticsearch/elasticsearch:7.10.2 7.10.2: Pulling from elasticsearch/elasticsearch ddf49b9115d7: Pull complete e736878e27ad: Pull complete 7487c9dcefbe: Pull complete 9ccb7e6e1f0c: Pull complete dcec6dec98db: Pull complete 8a10b4854661: Pull complete 1e595aee1b7d: Pull complete 06cc198dbf22: Pull complete 55b9b1b50ed8: Pull complete Digest: sha256:d528cec81720266974fdfe7a0f12fee928dc02e5a2c754b45b9a84c84695bfd9 Status: Downloaded newer image for docker.elastic.co/elasticsearch/elasticsearch:7.10.2 docker.elastic.co/elasticsearch/elasticsearch:7.10.2
-
Run Elasticsearch on a single node cluster
docker run -d --rm -p 9200:9200 --name elasticsearch_7_10_2 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.10.2
-
Check if the Elasticsearch container is up and running
$ curl -X GET 'localhost:9200/_cat/nodes?v=true' ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name 172.17.0.2 22 96 0 0.00 0.01 0.00 cdhilmrstw * 5160ddd7a72b
-
Shutdown the Elasticsearch container
docker container stop elasticsearch_7_10_2
Last active
May 9, 2023 21:19
-
-
Save roalcantara/4a807656c1176bb59c9cde0ae369a5ef to your computer and use it in GitHub Desktop.
Elasticsearch: Setup and Quickstart
-
Check the latest elasticsearch version
$ brew info elasticsearch elasticsearch: stable 7.10.2 (bottled) Distributed search & analytics engine https://www.elastic.co/products/elasticsearch Deprecated because it is switching to an incompatible license! Not installed From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/elasticsearch.rb License: Apache-2.0 ==> Dependencies Build: gradle ✘ Required: openjdk ✘ ==> Caveats Data: /usr/local/var/lib/elasticsearch/ Logs: /usr/local/var/log/elasticsearch/elasticsearch_roalcantara.log Plugins: /usr/local/var/elasticsearch/plugins/ Config: /usr/local/etc/elasticsearch/ To have launchd start elasticsearch now and restart at login: brew services start elasticsearch Or, if you don't want/need a background service you can just run: elasticsearch
-
Install Elasticsearch
brew install elasticsearch
-
Start the Elasticsearch service
brew services start elasticsearch
-
Check if Elasticsearch is up and running
$ curl -X GET 'localhost:9200/_cat/nodes?v=true' ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name 172.17.0.2 22 96 0 0.00 0.01 0.00 cdhilmrstw * 5160ddd7a72b
-
Stop the Elasticsearch service
brew services stop elasticsearch
-
curl -X POST http://localhost:9200/pokemons/_doc/100 \ --header 'content-type: application/json' \ --data '{"code": 100,"name": "soundproof","height": 5,"weight": 104,"created_at": "2021-02-04T13:31:42.843787"}'
-
curl http://localhost:9200/pokemons/_search
-
curl -X POST http://localhost:9200/pokemons/_search \ --header 'content-type: application/json' \ --data '{"query": {"term": {"code": 100}}}'
-
curl http://localhost:9200/pokemons/_doc/100
-
curl -X DELETE http://localhost:9200/pokemons/_doc/100
-
curl 'http://localhost:9200/_cat/nodes?v=true'
-
curl http://localhost:9200/_mapping
-
curl -X DELETE http://localhost:9200/pokemons
# elasticsearch.rest
@port = 9200
@hostname = localhost
@host = {{hostname}}:{{port}}
@index = pokemons
@id = 100
### CREATE a document
# https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html
POST http://{{host}}/{{index}}/_doc/{{id}}
content-type: application/json
{
"code": {{id}},
"name": "soundproof",
"height": 5,
"weight": 104,
"created_at": "2021-02-04T13:31:42.843787"
}
### GET documents
# https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html
GET http://{{host}}/{{index}}/_search
### GET documents by term
# https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
POST http://{{host}}/{{index}}/_search
content-type: application/json
{
"query": {
"term": {
"code": {{id}}
}
}
}
### GET document by id
# https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html
GET http://{{host}}/{{index}}/_doc/{{id}}
### DELETE document by id
# https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html
DELETE http://{{host}}/{{index}}/_doc/{{id}}
#### GET all running nodes
# https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-nodes.html
GET http://{{host}}/_cat/nodes?v=true
### GET an index's mapping
# https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html
GET http://{{host}}/_mapping
### DELETE an index
# https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html
DELETE http://{{host}}/{{index}}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment