tsar2512
tsar2512

Reputation: 2994

Exact match in elastic search on multiple key values

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.

Upvotes: 3

Views: 2693

Answers (1)

G Quintana
G Quintana

Reputation: 4667

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

Upvotes: 6

Related Questions