我正在使用Elasticsearch 6.2.3,并且试图对聚合进行过滤,以仅从存储桶中返回与所有键都不匹配的键。还是我需要做一个脚本并遍历存储桶以仅获取匹配项? 我的查询是:
{
"aggs" : {
"genres" : {
"nested" : {
"path" : "tags"
},
"aggs": {
"d":{
"terms" : { "field" : "tags.values.value.facet"
},
"aggs": {
"NAME": {
"filter": {
"prefix": {
"tags.values.value.facet": "Variatio"
}
}
}
}
}
}
}
}}
结果如下:
"aggregations": {
"genres": {
"doc_count": 285391,
"d": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 44437,
"buckets": [
{
"key": "null",
"doc_count": 251811,
"NAME": {
"doc_count": 0
}
},
{
"key": "MMAkku",
"doc_count": 15870,
"NAME": {
"doc_count": 0
}
},
{
"key": "MMBaden",
"doc_count": 15870,
"NAME": {
"doc_count": 0
}
},
{
"key": "MMEttlingen",
"doc_count": 15870,
"NAME": {
"doc_count": 0
}
},
{
"key": "MMEurope",
"doc_count": 15870,
"NAME": {
"doc_count": 0
}
},
{
"key": "MMGermany",
"doc_count": 15870,
"NAME": {
"doc_count": 0
}
},
{
"key": "MMKarlsruhe",
"doc_count": 15870,
"NAME": {
"doc_count": 0
}
}
}
但是我只想查看仅与过滤器中的单词匹配的键。 有什么建议吗?
谢谢
答案 0 :(得分:0)
尝试一下
{
"aggs": {
"facets": {
"filter": {
"prefix": {
"tags.values.value.facet": "Variatio"
}
},
"aggs": {
"facets_count": {
"terms": {
"field": "tags.values.value.facet"
}
}
}
}
}
}