How can i filter on my suggest list


(Jacques Du Plessis) #1

I have read quite a few articles saying that you can not combine queries with suggesters.
https://github.com/elastic/elasticsearch/issues/19143 is this still true? (old)

If so, what would be the best way to filter on the suggest list? I have a requirement to have suggesters for company names. But the logged in person might only have access to certain companies. I would to be able to do it with my query.

GET company/_search
{
  "suggest": {
    "company-suggest": {
      "prefix": "trans",
      "completion": {
        "field": "companyName.completion",
        "fuzzy": {
          "fuzziness": 1
        }
      }
    }
  }
}

The other option is "Dirty" is to just filter it afterwards either server-side or clientside , which i dont mind just want to make sure i am doing it the right way


(Jacques Du Plessis) #2

OK, so figured it out. Filters do not work in Completion Suggester. But Completion Suggester provides Context Suggester, which are basically filters for completion fields.
Updated my query as follows.

GET company/_search
{
  "suggest": {
    "company-suggest": {
      "prefix": "sky",
      "completion": {
        "field": "companyName.completion",
        "contexts": {
          "companyGroupId": [
            "1595"
          ]
        },
        "fuzzy": {
          "fuzziness": 1
        }
      }
    }
  }
}

Now i get the desired result, If i am missing anything please let me know


(system) #3

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