gpt4 book ai didi

elasticsearch - 在 elasticsearch 中查找不同的值,而不是不同的计数

转载 作者:行者123 更新时间:2023-11-29 02:43:10 25 4
gpt4 key购买 nike

Elasticsearch documentation 建议* 他们的代码

*文档已修复

GET /cars/transactions/_search?search_type=count
{
"aggs": {
"distinct_colors": {
"cardinality": {
"field": "color"
}
}
}
}

对应sql查询

SELECT DISTINCT(color) FROM cars

但实际上对应的是

SELECT COUNT(DISTINCT(color)) FROM cars

我不想知道我有多少个不同的值,但我不想知道这些不同的值是什么。有人知道如何实现吗?

最佳答案

使用 terms aggregationcolor 字段上。并且您需要注意如何分析您希望获得不同值的字段,这意味着您需要确保在索引时没有对其进行标记化,否则聚合中的每个条目都将是一个不同的术语,它是字段内容。

如果您仍然想要标记化并使用 terms 聚合,您可能需要查看该字段的 not_analyzed 类型的索引,并且可能使用 multi fields .

汽车术语聚合:

GET /cars/transactions/_search?search_type=count
{
"aggs": {
"distinct_colors": {
"terms": {
"field": "color",
"size": 1000
}
}
}
}

关于elasticsearch - 在 elasticsearch 中查找不同的值,而不是不同的计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28189725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com