ElasticSearch整个字段聚合 [英] ElasticSearch terms aggregation by entire field
问题描述
如何编写一个考虑整个字段值而不是单个令牌的ElasticSearch术语聚合查询?例如,我想按城市名称聚合,但以下返回新
, york
, san
和 francisco
作为单独的桶,而不是纽约
和 san francisco
作为预期的桶。
curl -XPOSThttp:// localhost :9200 / cities / _search-d'
{
size:0,
aggs:{
cities:{
:{
field:city,
min_doc_count:10
}
}
}
}'
您应该在映射中解决这个问题。添加not_analyzed字段。您可以创建多个字段,如果您还需要分析的版本。
相册:{
city :string,
fields:{
raw:{
type:string,
index:not_analyzed
}
}
}
现在在city.raw上创建你的汇总p>
How can I write an ElasticSearch term aggregation query that takes into account the entire field value, rather than individual tokens? For example, I would like to aggregate by city name, but the following returns new
, york
, san
and francisco
as individual buckets, not new york
and san francisco
as the buckets as expected.
curl -XPOST "http://localhost:9200/cities/_search" -d'
{
"size": 0,
"aggs" : {
"cities" : {
"terms" : {
"field" : "city",
"min_doc_count": 10
}
}
}
}'
You should fix this in your mapping. Add a not_analyzed field. You can create the multi field if you also need the analyzed version.
"album": {
"city": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
Now create your aggregate on city.raw
这篇关于ElasticSearch整个字段聚合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!