簡體   English   中英

使用Elasticsearch DSL Python的復合Elasticsearch聚合

[英]Composite Elasticsearch Aggregations using Elasticsearch DSL Python

我有以下查詢在這里工作正常:

{
   "aggs":{
      "category_terms":{
         "terms":{
            "field":"Category"
         },
         "aggs":{
            "style_per_category":{
               "terms":{
                  "field":"Style"
               }
            }
         }
      }
   }
}

我正在嘗試將其轉換為Elasticsearch DSL Python,但是我得到的並行聚合不是復合的:

a_cat = A('terms', field='Category')
a_style = A('terms', field='Style')

s.aggs.bucket('category_terms', a_cat)
s.aggs.bucket('style_per_category', a_style)

response = s.execute()

我正在尋找的輸出是這樣的:

"aggregations": {
    "category_terms": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 2727399,
      "buckets": [
        {
          "key": "Tops",
          "doc_count": 3131952,
          "style_per_category": {
            "doc_count_error_upper_bound": 14,
            "sum_other_doc_count": 129758,
            "buckets": [
              {
                "key": "T-Shirts",
                "doc_count": 940725
              },
...

嘗試這樣:

s.aggs.bucket('category_terms', a_cat)
   .bucket('style_per_category', a_style)

更多信息可以在這里找到

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM