If you want to run elasticsearch in docker you need to use a specific tag, the latest (at the time of writing) is 8.10.4, so let’s start by pulling that tag using
docker pull elasticsearch:8.10.4
I’ve going to connect Kibana to this instance later, so let’s create a network as for the two to work with. I’m calling mine kibana-network.
docker network create kibana-network
Once completed, run the following to start up elastic search.
Note: xpack.security.enabled=false turns off https for testing locally
docker run -d --name elasticsearch --net kibana-network -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "xpack.security.enabled=false" elasticsearch:8.10.4
We want to check this is working so let’s use CURL to call the elastic search instance, i.e.
curl -X GET http://localhost:9200/_cat/nodes?v
Or from you browser
http://localhost:9200/_cat/health
If all worked, we should see something like
1699220835 21:47:15 docker-cluster yellow 1 1 28 28 0 0 1 0 - 96.6%
Before we move on let’s add some data into our instance, we’ll start by adding an index (again we’ll use CURL),
curl -X PUT http://localhost:9200/myservice
We should see a response which looks something like this
response: {"acknowledged":true,"shards_acknowledged":true,"index":"myservice"}
Now to add some initial data
curl -X POST -H 'Content-Type: application/json' -d '{ "name": "Debug", "description": "This is a debug message", "code": 1, "id": 2}'
If you add a few more entries then we can try a query via CURL to locate this one
curl -X GET "localhost:9200/myservice/_search?pretty" -H 'Content-Type: application/json' -d' { "query": { "match": { "id": "2" } } }'