Context Suggester contexts are filtering with OR instead of AND?


(Tobias Leitner) #1

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


(Michael Sander) #2

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:

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.

{
  "_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"
            ]
          }
        },
        ...
      ]
    }
  ]
}

(Cara) #3

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.


(Tobias Leitner) #4

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


(Abdon Pijpelink) #5

Hi Tobias,

There is an open enhancement request Github issue here: 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).


(Abdon Pijpelink) #6

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

More info in this issue: https://github.com/elastic/elasticsearch/issues/21291


Context Suggester combinations
(system) #7

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