elasticsearch - Elasticsearch返回不同的结果

标签 elasticsearch distinct

这是我的ES查询:

  {
    "fields": [
      "news.authorname.raw",
      "news.authorid"
    ],
    "query": {
      "filtered": {
        "filter": {
          "terms": {
            "news.authorid": [
              1,
              2
            ]
          }
        }
      }
    }
  }

通过此查询,我得到了对{authorid,authorname}的列表。该列表具有重复的{authorid,authorname}值,我只需要获取相同的列表即可,没有重复。这似乎没有那么困难,或者至少不是我今天早上所想的那样。我对ES的了解很少,而且缺乏文档,这使我迫切希望找到解决此类琐碎问题的解决方案。

当然,我可以获取整个列表并通过代码删除重复项,但是如果可能的话,我宁愿不接收不必要的数据以将其删除。

任何人都可以帮上忙吗?我应该使用其他方法吗?

提前致谢!!

最佳答案

我建议使用source filtering:

  {
    "_source": [ "news.authorname.raw", "news.authorid" ],
    "query": {
      "filtered": {
        "filter": {
          "terms": {
            "news.authorid": [
              1,
              2
            ]
          }
        }
      }
    }
  }

它通常比字段容易处理,而字段有时看起来确实像笛卡尔积。

关于elasticsearch - Elasticsearch返回不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27865807/

相关文章:

Elasticsearch search_after,不使用 _id 作为 tie_breaker_field 吗?

sql - 使用 GROUP BY 子句时 SELECT DISTINCT 是否总是多余的?

sql - DISTINCT 与 PARTITION BY 对比 GROUPBY

c# - IQueryable.Distinct() 与 List.Distinct()

iphone - 通过核心数据的不同计数,NSExpression 到 NSFetchedResultsController

mysql - 如何创建模拟我的 mysql 数据库的 Elasticsearch 索引

java - 在 Elasticsearch 中将数字字段索引为 int 和 string

sql - 如何从列表中删除所有重复的对?

docker - 如何安装Xpack在Docker上运行的Elasticsearch?

elasticsearch - 在 Elasticsearch 查询中获取数据而不匹配完整字符串