Matching multiple attribs with elasticsearch

Tuan Anh Tran

So i have a bunch of records like {A: x, B: y}.

I would like to construct a search query that match both A and B attrib.

However, adding 1 more criteria into match, the query would fail to parse.

This works.

{
   "query" : {
       "match": {
           "A": "x"
       }
   }
}

This doesn't.

{
   "query" : {
       "match": {
           "A": "x",
           "B": "y"
       }
   }
}
Duc.Duong

It should be like this:

{
  "query": {
   "bool": {
      "must": [
          {
             "match": {"A": "x"}
          },
          {
             "match": {"B": "y"}
          }
       ]
    }
   }
 }

Use must to AND all your match clauses, use should to OR all match clauses.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related