使用完成提示器时,如何获得无重复的独特建议? [英] How can i get unique suggestions without duplicates when i use completion suggester?

查看:73
本文介绍了使用完成提示器时,如何获得无重复的独特建议?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的环境中使用的是Elastic 5.1.1.我在具有字符串数组的字段名称post_hashtags上选择了完成建议,可以在上面提出建议.我收到以下针对前缀"inv"的响应

I am using elastic 5.1.1 in my environment. I have chosen completion suggester on a field name post_hashtags with an array of strings to have suggestion on it. I am getting response as below for prefix "inv"

要求:

POST hashtag/_search?pretty&&filter_path=suggest.hash-suggest.options.text,suggest.hash-suggest.options._source
{"_source":["post_hashtags" ],

"suggest": {
    "hash-suggest" : {
        "prefix" : "inv",
        "completion" : {
            "field" : "post_hashtags"
        }
    }
}

响应:

{
  "suggest": {
    "hash-suggest": [
      {
        "options": [
          {
            "text": "invalid",
            "_source": {
              "post_hashtags": [
                "invalid"
              ]
            }
          },
          {
            "text": "invalid",
            "_source": {
              "post_hashtags": [
                "invalid",
                "coment_me",
                "daya"
              ]
            }
          }
        ]
      }
    ]
  }

此处"invalid"被返回两次,因为它也是其他文档中相同字段"post_hashtags"的输入字符串.

Here "invalid" is returned twice because it is also a input string for same field "post_hashtags" in other document.

问题是,如果相同索引中的1000个文档中存在相同的无效"输入字符串,那么我会得到1000个重复的建议,这是巨大且不需要的.

Problems is if same "invalid" input string present in 1000 documents in same index then i would get 1000 duplicated suggestions which is huge and not needed.

我可以在完成类型的字段上应用聚合吗?

Can I apply an aggregation on a field of type completion ?

即使我在相同索引的多个文档中为特定字段指定了相同的输入字符串,有什么办法可以得到唯一的建议而不是重复的文本字段?

Is there any way I can get unique suggestion instead of duplicated text field, even though if i have same input string given to a particular field in multiple documents of same index ?

推荐答案

ElasticSearch 6.1引入了

ElasticSearch 6.1 has introduced the skip_duplicates operator. Example usage:

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

这篇关于使用完成提示器时,如何获得无重复的独特建议?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆