【发布时间】:2016-02-20 17:54:52
【问题描述】:
我正在尝试做一些聚合查询并遇到一些问题。
GET /my_index/_search
{
"size" : 0,
"aggs":{
"group_by":{
"terms": {
"field" : "category"
}
}
}
}
这是让我回来:
"hits": {
"total": 180,
"max_score": 0,
"hits": []
},
"aggregations": {
"group_by": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 1,
"buckets": [
{
"key": "pf_rd_m",
"doc_count": 139
},
{
"key": "other",
"doc_count": 13
},
{
"key": "_encoding",
"doc_count": 12
},
{
"key": "ie",
"doc_count": 10
},
{
"key": "cadeaux",
"doc_count": 2
},
{
"key": "cartes",
"doc_count": 2
},
{
"key": "cheques",
"doc_count": 2
},
{
"key": "home",
"doc_count": 2
},
{
"key": "nav_logo",
"doc_count": 1
},
{
"key": "ref",
"doc_count": 1
}
]
}
}
如您所见,这告诉我有 180 个文档,但如果我计算存储桶中每个键的 doc_count 总和,我会发现更多元素...
这当然适用于弹性搜索标记化机制 (https://www.elastic.co/guide/en/elasticsearch/guide/current/aggregations-and-analysis.html)
所以我尝试了这个 es 帖子中的解决方案,但仍然无法正常工作。这是我的地图
"properties":{
"status":{
"type":"integer",
"index":"analyzed"
},
"category":{
"type":"string",
"fields": {
"raw" : {
"type": "string",
"index": "not_analyzed"
}
}
},
"dynamic_templates": [
{ "notanalyzed": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}
]
}
如您所见,我有一个名为“类别”的字段。并将“raw”添加为 not_analyzed 字符串,但仍然返回错误的数字。
当我尝试这个时:
GET /my_index/_search
{
"size" : 0,
"aggs":{
"group_by":{
"terms": {
"field" : "category.raw"
}
}
}
}
返回:
"hits": {
"total": 180,
"max_score": 0,
"hits": []
},
"aggregations": {
"group_by": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
}
}
这很奇怪。有什么帮助吗?
【问题讨论】: