Elastic Search Query with multiple conditions

Viewed 458

I am new to elastic search and I need help for below scenario:

I have two fields tag and author. I want to search the data with condition

(tag="1" and (author="A" or author="B")) or (tag="2" and (author="A" or author="C")) or tag="3"

Please give a outline of how to frame the Elastic Search query.

1 Answers

Use the query string query:

POST your-index/_search
{
  "query": {
    "query_string": {
      "query": "(tag:'1' AND author:('A' OR 'B')) OR (tag:'2' AND author:('A' OR 'C'))"
    }
  }
}
Related