How can i get unique suggestions without duplicates when i use completion suggester?

北城以北 提交于 2019-12-05 03:25:46

ElasticSearch 6.1 has introduced the skip_duplicates operator. Example usage:

{
  "suggest": {
    "autocomplete": {
      "prefix": "MySearchTerm",
      "completion": {
        "field": "name",
        "skip_duplicates": true
      }
    }
  }
}

Edit: This answer only applies to Elasticsearch 5

No, you cannot de-duplicate suggestion results. The autocomplete suggester is document-oriented in Elasticsearch 5 and will thus return suggestions for all documents that match.

In Elasticsearch 1 and 2, the autocomplete suggester automatically de-duplicated suggestions. There is an open Github ticket to bring back this functionality, and it looks like it is possible to do so in a future version.

For now, you have two options:

  1. Use Elasticsearch version 1 or 2.
  2. Use a different suggestion implementation not based on the autocomplete suggester. The only semi-official suggestion I have seen so far involve putting your suggestion strings in a separate index.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!