Learn ElasticSearch Cluster
- Install docker and docker-compose
- Install postman
- Run command: docker-compose up -d
- Import postman collection to postman
- Minimum (N/2)+1 nodes to start the cluster.
- If we have 3 nodes, at least 2 nodes must run on startup
GET http://localhost:9201/_cat/nodes?v
PUT http://localhost:9202/learn_es_index
- Index information will exist across nodes in the cluster
GET http://localhost:9203/learn_es_index
Get Indices Info in Cluster
http://localhost:9203/_cat/indices?v
Get Shards Info in Cluster (Document Distribution)
http://localhost:9203/_cat/shards?v
Performing CRUD operations
PUT http://localhost:9203/learn_es_index/_doc/1
{
"programming_language": "java",
"typing_type": "static"
}
PUT http://localhost:9203/learn_es_index/_doc/2
{
"programming_language": "golang",
"typing_type": "static"
}
PUT http://localhost:9203/learn_es_index/_doc/3
{
"programming_language": "kotlin",
"typing_type": "static"
}
Create Document - POST (auto increment)
POST http://localhost:9203/learn_es_index/_doc
{
"programming_language": "python",
"typing_type": "dynamic"
}
GET http://localhost:9203/learn_es_index/_doc/3
GET http://localhost:9203/learn_es_index/_doc/dummy_id
PUT http://localhost:9203/learn_es_index/_doc/1
{
"programming_language": "swift",
"typing_type": "static"
}
DELETE http://localhost:9203/learn_es_index/_doc/KVdu43wBXN6h2Uu3uG1t
Performing Search operations
GET http://localhost:9203/_search
GET http://localhost:9203/learn_es_index/_search
GET http://localhost:9203/learn_es_index/_search
{
"query": {
"match": {
"typing_type": "dynamic"
}
}
}
GET http://localhost:9203/learn_es_index/_search
{
"query": {
"bool": {
"must": {
"match": {
"typing_type": "static"
}
}
}
}
}
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"
}
}
]
}
}
}
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"
}
}
}
}