0

我有以下查询在这里工作正常:

{
   "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
              },
...
4

1 回答 1

1

试试这样:

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

更多信息可以在这里找到

于 2019-05-21T06:06:51.957 回答