Exact match in elastic search on multiple key values

Viewed 2184

I am trying to write a query in elasticsearch with an exact match on multiple fields

I have the following query for an exact match for a single field:

GET /index/data/_search
{
    "query": {
        "term": {
            "table":"abc"   
        }
    }
}

Here the key is "table" and the value is "abc". I would like to add another key called "chair" with value "def for the exact match query.

1 Answers

Use a bool+must or bool+filter query, both act as logical and operator:

GET /index/data/_search
{
    "query": {
        "bool": {
             "must": [
                  {
                      "term": {
                          "table":"abc"   
                  },
                  {
                      "term": {
                          "chair":"def"   
                  }
            ]
        }
    }
}
Related