Learn ElasticSearch Cluster

Setup

  1. Install docker and docker-compose
  2. Install postman
  3. Run command: docker-compose up -d
  4. Import postman collection to postman



Info

  • Minimum (N/2)+1 nodes to start the cluster.
  • If we have 3 nodes, at least 2 nodes must run on startup



API

Check Node Port

http://localhost:9201

Image



Get Cluster's Node Info

GET http://localhost:9201/_cat/nodes?v

Image



Create Index

PUT http://localhost:9202/learn_es_index

Image



Get Detailed Index

  • Index information will exist across nodes in the cluster
GET http://localhost:9203/learn_es_index

Image



Get Indices Info in Cluster

http://localhost:9203/_cat/indices?v

Image



Get Shards Info in Cluster (Document Distribution)

http://localhost:9203/_cat/shards?v

Image




Performing CRUD operations

Create Document - PUT

PUT http://localhost:9203/learn_es_index/_doc/1
{
    "programming_language": "java",
    "typing_type": "static"
}

Image

PUT http://localhost:9203/learn_es_index/_doc/2
{
    "programming_language": "golang",
    "typing_type": "static"
}

Image

PUT http://localhost:9203/learn_es_index/_doc/3
{
    "programming_language": "kotlin",
    "typing_type": "static"
}

Image



Create Document - POST (auto increment)

POST http://localhost:9203/learn_es_index/_doc
{
    "programming_language": "python",
    "typing_type": "dynamic"
}

Image



Read Document

GET http://localhost:9203/learn_es_index/_doc/3

Image

GET http://localhost:9203/learn_es_index/_doc/dummy_id 

Image



Update Document

PUT http://localhost:9203/learn_es_index/_doc/1
{
    "programming_language": "swift",
    "typing_type": "static"
}

Image



Delete Document

DELETE http://localhost:9203/learn_es_index/_doc/KVdu43wBXN6h2Uu3uG1t

Image




Performing Search operations

Search All Index

GET http://localhost:9203/_search

Image



Search Specific Index

GET http://localhost:9203/learn_es_index/_search

Image



Search Query Match

GET http://localhost:9203/learn_es_index/_search
{
    "query": {
        "match": {
            "typing_type": "dynamic"
        }
    }
}

Image



Search Bool Query (must)

GET http://localhost:9203/learn_es_index/_search
{
    "query": {
        "bool": {
            "must": {
                "match": {
                    "typing_type": "static"
                }
            }
        }
    }
}

Image



Search Bool Query (should)

GET http://localhost:9203/learn_es_index/_search
{
    "query": {
        "bool": {
            "must": [],
            "must_not": [],
            "should": [
                {
                    "match": {
                        "programming_language": "golang"
                    }
                },
                {
                    "match": {
                        "programming_language": "kotlin"
                    }
                }
            ]
        }
    }
}

Image



Search Aggregation

http://localhost:9203/learn_es_index/_search
{
    "query": {
        "bool": {
            "must": []
        }
    },
    "aggs": {
        "result_typing_type": {
            "terms": {
                "field": "typing_type.keyword"
            }
        },
        "result_programming_lang": {
            "terms": {
                "field": "programming_language.keyword"
            }
        }
    }
}

Image