跳过Elasticsearch搜索结果中的字段重复项 [英] Skip duplicates on field in a Elasticsearch search result

查看:39
本文介绍了跳过Elasticsearch搜索结果中的字段重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以删除给定字段上的重复项?

Is it possible to remove duplicates on a given field?

例如以下查询:

{
  "query": {
    "term": {
      "name_admin": {
        "value": "nike"
      }
    }
  },
  "_source": [
    "name_admin",
    "parent_sku",
    "sku"
  ],
  "size": 2
}

正在检索

"hits" : [
      {
        "_index" : "product",
        "_type" : "_doc",
        "_id" : "central30603",
        "_score" : 4.596813,
        "_source" : {
          "parent_sku" : "SSP57",
          "sku" : "SSP57816401",
          "name_admin" : "NIKE U NSW PRO CAP NIKE AIR"
        }
      },
      {
        "_index" : "product",
        "_type" : "_doc",
        "_id" : "central156578",
        "_score" : 4.596813,
        "_source" : {
          "parent_sku" : "SSP57",
          "sku" : "SSP57816395",
          "name_admin" : "NIKE U NSW PRO CAP NIKE AIR"
        }
      }
    ]

我想跳过 parent_sku 上的重复项,因此每个 parent_sku 只能得到一个结果,就像 suggestion 所做的那样,这是可能的"skip_duplicates":是.

I'd like to skip duplicates on parent_sku so I only have one result per parent_sku like it's possible with suggestion by doing something like "skip_duplicates": true.

我知道我可以通过 aggregation 来实现此目标,但是我想坚持搜索,因为我的查询有点复杂,而且我正在使用 scroll 不适用于聚合的API.

I know I cloud achieve this with an aggregation but I'd like to stick with a search, as my query is a bit more complicated and as I'm using the scroll API which doesn't work with aggregations.

推荐答案

上面的查询将返回一个文档,该文档的名称为 parent_sku .

The above query will return one document par parent_sku.

这篇关于跳过Elasticsearch搜索结果中的字段重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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