user3170702
user3170702

Reputation: 2061

Equivalent of boolean or in ElasticSearch

I currently search my data for exact matches on one term like this:

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "term_a": "xxxxx"
          }
        }
      ]
    }
  }
}

However, I want to be able to search on multiple terms and get all documents that match at least one. So in SQL speak term_a = 'xxxxx' or term_b = 'yyyyy'. How can I do this?

Upvotes: 0

Views: 27

Answers (1)

Andrei Stefan
Andrei Stefan

Reputation: 52368

Then you can use a bool with should statements for each term:

"bool": {
  "should": [
    {
      "term": {
        "term_a": "xxxxx"
      }
    },
    {
      "term": {
        "term_b": "yyyyy"
      }
    }
  ]
}

If you want to search multiple terms in the same field then you can use a terms query.

Upvotes: 3

Related Questions