【发布时间】:2019-08-25 03:23:18
【问题描述】:
我正在尝试找出一种方法来查找最流行的术语及其在 ElasticSearch 中的用法。 Terms Aggregation 非常接近,但返回该术语出现的文档数,而不是该术语出现的次数。
例如,假设已经创建了一个适当的索引来索引这些示例文档:
{ text: 'one two two' }
{ text: 'two three' }
然后执行以下搜索:
{
aggregations: {
popular_terms: {
terms: {
field: 'text'
}
}
}
}
将返回:
... {
buckets: [
{ key: 'two', value: 2 },
{ key: 'one', value: 1 },
{ key: 'three', value: 1 }
]
}
是否可以以类似的方式使用聚合计数实例进行搜索?那么在这个例子中返回3 的值'two',因为它在第一个文档中出现了两次?
【问题讨论】:
标签: elasticsearch