# How does the context influence the bool query?

**URL:** <https://discuss.elastic.co/t/how-does-the-context-influence-the-bool-query/66209>\
**Category:** Elasticsearch\
**Created:** [November 16, 2016, 7:09am UTC](https://discuss.elastic.co/t/how-does-the-context-influence-the-bool-query/66209 "2016-11-16T07:09:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndreKR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrekr/32/6233_2.png) [@AndreKR](https://discuss.elastic.co/u/AndreKR)\
**Post date:** [November 16, 2016, 7:09am UTC](https://discuss.elastic.co/t/how-does-the-context-influence-the-bool-query/66209/1 "2016-11-16T07:09:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![AndreKR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrekr/32/6233_2.png) [@AndreKR](https://discuss.elastic.co/u/AndreKR)\
**Post date:** [November 16, 2016, 8:18am UTC](https://discuss.elastic.co/t/how-does-the-context-influence-the-bool-query/66209/2 "2016-11-16T08:18:08Z")

</div>

Never mind, [it's there](https://www.elastic.co/guide/en/elasticsearch/reference/2.1/query-dsl-bool-query.html)... 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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 14, 2016, 8:18am UTC](https://discuss.elastic.co/t/how-does-the-context-influence-the-bool-query/66209/3 "2016-12-14T08:18:09Z")

</div>

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