我正在ElasticSearch(版本:6)中运行聚合查询。我有很多文档,每个文档都有一个分数some_score
和一个文本数组keywords
。现在,我试图获取所有唯一关键字的列表,每个关键字以及属于扇区category1
和category2
的文档数一起列出。使用得分(<50&> 50)将文档分为多个扇区。我可以正常获取数据,但是当我运行bucket_script
聚合来为每个存储桶(或关键字)计算some_metric
时,bucket_script
结果不包括在结果中。也没有显示错误。
查询:
curl -XGET "http://localhost:9200/my_index/_search" -H 'Content-Type: application/json' -d'
{
"size": 0,
"aggs": {
"keywords_by_sector": {
"terms": {
"field": "keywords.keyword",
"size": 100
},
"aggs": {
"sectors": {
"filters": {
"filters": {
"category1": {
"range": {
"some_score": {
"from": 0,
"to": 50
}
}
},
"category2": {
"range": {
"some_score": {
"from": 51,
"to": 100
}
}
}
}
}
},
"some_metric": {
"bucket_script": {
"buckets_path": {
"varr": "sectors['category1']>_count"
},
"script": "params.varr*10"
}
}
}
}
}
}'
结果:
{
"took" : 12,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 6,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"keywords_by_sector" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "keyword1",
"doc_count" : 2,
"sectors" : {
"buckets" : {
"category1" : {
"doc_count" : 0
},
"category2" : {
"doc_count" : 1
}
}
},
/* I expect some_metric to be included here */
},
...
...
]
}
}
}
我出了什么问题?为什么该字段未包含在结果中而没有任何错误?