Skip to content

huynhsx/elasticsearch-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Elasticsearch with Docker

This guide will walk you through setting up Elasticsearch with Docker, using Docker Compose, and running queries using Dev Tools.

Table of Contents

  1. Usage
  2. Starting Docker
  3. Running Queries in Dev Tools

Usage

This setup uses Docker to run Elasticsearch and Kibana, allowing you to quickly set up a local environment for development and testing.

Starting Docker

1. Build the Docker images and start the services:

docker-compose up --build

2. Access Elasticsearch and Kibana:

Running Queries in Dev Tools

Once Kibana is up and running, you can use the Dev Tools to interact with Elasticsearch.

Sample CRUD Operations in Elasticsearch

1. Create

Create a record with ID 1

PUT /library/_doc/1
{
  "title": "Norwegian Wood",
  "name": {
    "first": "Haruki",
    "last": "Murakami"
  },
  "publish_date": "1987-09-04T00:00:00+0900",
  "price": 19.95
}

Create a record without an ID

POST /library/_doc/
{
  "title": "Kafka on the Shore",
  "name": {
    "first": "Haruki",
    "last": "Murakami"
  },
  "publish_date": "2002-09-12T00:00:00+0900",
  "price": 19.95
}

2. Search (Read)

Retrieve a record with ID 1

GET /library/_doc/1

Search for records with "Kafka" in the title

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
        }
      }
    ]
  }
}

3. Update

Update a record with ID 1

POST /library/_update/1
{
  "doc": {
    "price": 24.95
  }
}

4. Delete

Delete a record with ID 1

DELETE /library/_doc/1

About

elasticsearch-demo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published