是否可以按键过滤术语聚合?我在数组字段上进行了术语聚合,这导致了许多不必要的存储桶。 (即使我在查询中应用了过滤器)
例如,对于这样的结果:
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 9928,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"variables" : {
"buckets" : [ {
"key" : "00",
"doc_count" : 158
}, {
"key" : "1",
"doc_count" : 158
}, {
"key" : "2",
"doc_count" : 158
}, {
"key" : "3",
"doc_count" : 158
}, {
"key" : "4",
"doc_count" : 158
}, {
"key" : "5",
"doc_count" : 158
}, {
"key" : "6",
"doc_count" : 156
}, {
"key" : "7",
"doc_count" : 127
}, {
"key" : "8",
"doc_count" : 121
}, {
"key" : "9",
"doc_count" : 104
} ]
}
}
}
我想要做的是告诉ElasticSearch只保留桶= key = [1,2,3,4,5]。
更新
以下是我使用的查询:
POST xxtransaction/_search?ignore_unavailable=true
{
"size" : 0,
"timeout" : 30000,
"terminate_after" : 10000000,
"query" : {
"filtered" : {
"filter" : {
"and" : {
"filters" : [ {
"range" : {
"transaction_time" : {
"from" : 1459461600000,
"to" : 1459547999999,
"include_lower" : true,
"include_upper" : true
}
}
}, {
"term" : {
"site" : "xxx.com"
}
}, {
"terms" : {
"category_codes" : [ 1,2,3,4,5,6,7,8,9]
}
} ]
}
}
}
},
"aggregations" : {
"category_codes" : {
"terms" : {
"field" : "category_codes",
"size" : 20000
}
}
}
}