我正在嘗試做一些聚合查詢和encouter一些問題。elasticsearch aggs返回錯誤的計數編號
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的總和在我的水桶,我覺得更多的元素......
這肯定做elasticsearch標記化mecanism(https://www.elastic.co/guide/en/elasticsearch/guide/current/aggregations-and-analysis.html)
所以我tryed解決方案在這個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"
}
}
}
]
}
正如你所看到的,我有一個名爲「category」的字段。並將「raw」添加爲not_analyze字符串,但仍然返回錯誤的數字。
當我試試這個:
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": []
}
}
這是非常奇怪的。任何幫助?
謝謝您的答覆。我試了你的答案,但查詢返回給我一個arror。 解析失敗[無元素[shard_size]的解析器]]; }]「, 」status「:400 –
所以對不起,應該在聚合定義中。 – Hkntn
我怎麼能定義這個聚合?在我的映射或者其他地方?謝謝 –