volkodavs / elasticsearch-playground

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Elasticsearch Playground

Overvierw

This project starts 3 node elasticsearch cluster with Nobel laureates dataset.

{
  "year": "2019",
  "category": "chemistry",
  "laureates": [
    {
      "id": "976",
      "firstname": "John",
      "surname": "Goodenough",
      "motivation": "for the development of lithium-ion batteries",
      "share": "3"
    },
    
    ...
    
    ]
 }

How to start

docker-compose up

NOTE By default, a fresh new cluster created

Requirements

To run this project you should install:

  • docker
  • docker-compose

Elasticsearch Mapping

Nobel mapping

{
  "mappings": {
    "properties": {
      "year": { "type": "integer"},
      "category": {"type": "text"},
      "laureates": {
        "type": "nested", 
        "properties" : {
          "id": {"type": "long"},
          "firstname": {"type": "text"},
          "surname": {"type": "text"},
          "motivation": {"type": "text"},
          "share": {"type": "text"}
        }
      }
    }
  }
}

Query examples

Nested query

Search for the two Nobel laureates John Goodenough and M. Stanley Whittingham

curl --location --request GET 'http://localhost:9200/nobel/_search' \
--header 'Content-Type: application/json' \
--data-raw '{
    "query": {
        "bool": {
            "must": [
                {
                    "nested": {
                        "path": "laureates",
                        "query": {
                            "bool": {
                                "must": [
                                    {
                                        "match": {
                                            "laureates.firstname": "John"
                                        }
                                    },
                                    {
                                        "match": {
                                            "laureates.surname": "Goodenough"
                                        }
                                    }
                                ]
                            }
                        }
                    }
                },
                {
                    "nested": {
                        "path": "laureates",
                        "query": {
                            "bool": {
                                "must": [
                                     {
                                        "match": {
                                            "laureates.firstname": "M. Stanley"
                                        }
                                    },
                                    {
                                        "match": {
                                            "laureates.surname": "Whittingham"
                                        }
                                    }
                                ]
                            }
                        }
                    }
                }
            ]
        }
    }
}'

About


Languages

Language:Shell 92.3%Language:Dockerfile 7.7%