# Context Suggester contexts are filtering with OR instead of AND?

**URL:** <https://discuss.elastic.co/t/context-suggester-contexts-are-filtering-with-or-instead-of-and/79769>\
**Category:** Elasticsearch\
**Created:** [March 23, 2017, 3:53pm UTC](https://discuss.elastic.co/t/context-suggester-contexts-are-filtering-with-or-instead-of-and/79769 "2017-03-23T15:53:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tobias\_Leitner](https://avatars.discourse-cdn.com/v4/letter/t/48db29/32.png) [@Tobias\_Leitner](https://discuss.elastic.co/u/Tobias_Leitner)\
**Post date:** [March 23, 2017, 3:54pm UTC](https://discuss.elastic.co/t/context-suggester-contexts-are-filtering-with-or-instead-of-and/79769/1 "2017-03-23T15:54:00Z")

</div>

Hello Guys,

I just tried to use the context suggester in Elasticsearch 5.x with the option to filter for the contexts. In my Example I have 2 contexts defined and when I query for it, It will retrieve the document even if I just filtered for only a single contexts. So for me it looks like it is a OR Operation.  
I can remember using in in Elasticsearch 2.3 and it was definitly a AND Operation. Is there a way to retrieve the document back only if both contexts are found?

Thanks in advance,

Tobias

---

<div class="post-metadata">

**Author:** ![Michael\_Sander](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_sander/32/838_2.png) [@Michael\_Sander](https://discuss.elastic.co/u/Michael_Sander)\
**Post date:** [April 18, 2017, 1:15am UTC](https://discuss.elastic.co/t/context-suggester-contexts-are-filtering-with-or-instead-of-and/79769/2 "2017-04-18T01:15:03Z")

</div>

I just ran into this too, can anyone help? This seems like very bad behavior (there should at least be an option to do an AND).

As an example, this is a suggester query that I ran, requiring the `entity` context to be `party` AND the `court` context to be `SCOTUS`:

```auto
curl -XGET /[INDEX]/_suggest?pretty -d '{
  "suggest_party": {
    "completion": {
      "contexts": {
        "entity": {"context" : "party"},
        "court": {"context" : "SCOTUS"}
      },
      "field": "entity_suggest"
    },
    "text": "Sony"
  }
}'

```

These are the results I received, notice that all of them are missing the `party` context.

```auto
{
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "suggest_party" : [
    {
      "text" : "Sony",
      "offset" : 0,
      "length" : 4,
      "options" : [
        {
          "text" : "Sony",
          "_index" : "[INDEX]",
          "_type" : "modelresult",
          "_id" : "5220390770049024",
          "_score" : 1.0,
          "contexts" : {
            "court" : [
              "SCOTUS"
            ]
          }
        },
        {
          "text" : "Sony",
          "_index" : "[INDEX]",
          "_type" : "modelresult",
          "_id" : "4808872471560192",
          "_score" : 1.0,
          "contexts" : {
            "court" : [
              "SCOTUS"
            ]
          }
        },
        ...
      ]
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![cara-dev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cara-dev/32/17463_2.png) [@cara-dev](https://discuss.elastic.co/u/cara-dev)\
**Post date:** [April 18, 2017, 3:59pm UTC](https://discuss.elastic.co/t/context-suggester-contexts-are-filtering-with-or-instead-of-and/79769/3 "2017-04-18T15:59:24Z")

</div>

I've got the exact same issue. I'm migrating from version 2.3 to 5.3 and have found the 2 contexts are now used in an OR operation rather than an AND operation (as was the case in v2.3). I haven't yet figured out a solution and this will be a show stopper if not sorted out. Anyone know of a workaround or any ideas on what might work? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Tobias\_Leitner](https://avatars.discourse-cdn.com/v4/letter/t/48db29/32.png) [@Tobias\_Leitner](https://discuss.elastic.co/u/Tobias_Leitner)\
**Post date:** [May 15, 2017, 9:38am UTC](https://discuss.elastic.co/t/context-suggester-contexts-are-filtering-with-or-instead-of-and/79769/4 "2017-05-15T09:38:49Z")

</div>

Hi Elastic-Team,

I was told in the ElasticSearch Training to ask my questions in the forum about the context suggester, can anyone please help us with this topic?

Thank you in advance,  
Tobias

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [May 15, 2017, 12:42pm UTC](https://discuss.elastic.co/t/context-suggester-contexts-are-filtering-with-or-instead-of-and/79769/5 "2017-05-15T12:42:11Z")

</div>

Hi Tobias,

There is an open enhancement request Github issue here: [https://github.com/elastic/elasticsearch/issues/24421](https://github.com/elastic/elasticsearch/issues/24421)

You can track that issue to track progress, and the issue also provides a workaround that may work for you (concatenating contexts into a single value).

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [May 15, 2017, 12:45pm UTC](https://discuss.elastic.co/t/context-suggester-contexts-are-filtering-with-or-instead-of-and/79769/6 "2017-05-15T12:45:55Z")

</div>

In fact, it looks that there is some progress that may make its way into 5.5: [https://github.com/elastic/elasticsearch/pull/24565](https://github.com/elastic/elasticsearch/pull/24565)

More info in this issue: [https://github.com/elastic/elasticsearch/issues/21291](https://github.com/elastic/elasticsearch/issues/21291)

---

<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:** [June 12, 2017, 12:54pm UTC](https://discuss.elastic.co/t/context-suggester-contexts-are-filtering-with-or-instead-of-and/79769/7 "2017-06-12T12:54:39Z")

</div>

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