Q:

Elasticsearch - Using terms and bool at same time in filtered query gives error

I'm building query for search, but got stuck on searching for multiple values for one field (location). Such that, it can be more than one city.
My query looks like:
{
    "query" : {
        "filtered" : {
            "filter" : {
                "terms" : { 
                    "location" : [Baku, Paris, London]
                },
                "bool" : {
                    "must" : ...
                }
            }
        }
    }
}

Result is 400: SearchPhaseExecutionException ... QueryParsingException
What can be the reason?
Terms documentation I used: https://www.elastic.co/guide/en/elasticsearch/guide/current/_finding_multiple_exact_values.html

A:

Your terms filter must be located inside the bool/must clause, like below. And don't forget to surround your city names with double quotes as well.
{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "must": [
            {
              "terms": {
                "location": [ "Baku", "Paris", "London" ]
              }
            },
            ...
          ]
        }
      }
    }
  }
}

