How does the context influence the bool query?

In my index, there is a document that has ident_key = a, but none with ident_key = b.

Now this query returns one hit:

GET _search
{
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "ident_key": "a"
          }
        }
      ],
      "should": [
        {
          "term": {
            "ident_key": "b"
          }
        }
      ]
    }
  }
}

But this query returns no hits:

GET _search
{
  "filter": { 
    "bool": {
      "filter": [
        {
          "term": {
            "ident_key": "a"
          }
        }
      ],
      "should": [
        {
          "term": {
            "ident_key": "b"
          }
        }
      ]
    }
  }
}

The only difference is the outermost filter instead of query.

I don't understand this behavior. Does a bool query work differently in query context than in filter context (apart from the scoring)?

This is Elasticsearch 2.1.

Never mind, it's there... in a box... with a big exclamation mark:

If this query is used in a filter context and it has should clauses then at least one should clause is required to match.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.