This guide will walk you through setting up Elasticsearch with Docker, using Docker Compose, and running queries using Dev Tools.
This setup uses Docker to run Elasticsearch and Kibana, allowing you to quickly set up a local environment for development and testing.
docker-compose up --build
- Elasticsearch: http://localhost:9200
- Kibana Dev Tools: http://localhost:5601/app/dev_tools#/console
Once Kibana is up and running, you can use the Dev Tools to interact with Elasticsearch.
Sample CRUD Operations in Elasticsearch
PUT /library/_doc/1
{
"title": "Norwegian Wood",
"name": {
"first": "Haruki",
"last": "Murakami"
},
"publish_date": "1987-09-04T00:00:00+0900",
"price": 19.95
}
POST /library/_doc/
{
"title": "Kafka on the Shore",
"name": {
"first": "Haruki",
"last": "Murakami"
},
"publish_date": "2002-09-12T00:00:00+0900",
"price": 19.95
}
GET /library/_doc/1
GET /library/_search
{
"query": {
"match": {
"title": "Kafka"
}
}
}
Sample search response
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 0.60996956,
"hits": [
{
"_index": "library",
"_id": "X87wepABDtAA5KxfoOXv",
"_score": 0.60996956,
"_source": {
"title": "Kafka on the Shore",
"name": {
"first": "Haruki",
"last": "Murakami"
},
"publish_date": "2002-09-12T00:00:00+0900",
"price": 19.95
}
}
]
}
}
POST /library/_update/1
{
"doc": {
"price": 24.95
}
}
DELETE /library/_doc/1