简体   繁体   English

Elasticsearch-如何使聚合仅返回匹配的键

[英]Elasticsearch- How to make the aggregation to return only the key matched

I'm using elasticsearch 6.2.3 and i'm trying to make a filter on the aggregation to return only the keys matched not all of them from the buckets. 我正在使用Elasticsearch 6.2.3,并且试图对聚合进行过滤以仅返回与存储桶中未匹配的所有键不匹配的键。 Or maybe i need to do a script and iterate over the buckets to get only the match? 还是我需要做一个脚本并遍历存储桶以仅获取匹配项? My query is: 我的查询是:

  {
"aggs" : {
    "genres" : {
           "nested" : {
            "path" : "tags"
        },
        "aggs": {
          "d":{
        "terms" : { "field" : "tags.values.value.facet"
        },
        "aggs": {
          "NAME": {
            "filter": {
              "prefix": {
                "tags.values.value.facet": "Variatio"
              }
            }
          }
        }
      }
    }
  }                 
}}

And the result looks like that: 结果看起来像这样:

"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
        }
      }
      }

But i want to see only the keys that matches only the word from the filter. 但我只想查看仅与筛选器中的单词匹配的键。 Any suggestions? 有什么建议么?

Thank you 谢谢

Try this 尝试这个

{
  "aggs": {
    "facets": {
      "filter": {
        "prefix": {
          "tags.values.value.facet": "Variatio"
        }
      },
      "aggs": {
        "facets_count": {
          "terms": {
            "field": "tags.values.value.facet"
          }
        }
      }
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM