【问题标题】:Composite Elasticsearch Aggregations using Elasticsearch DSL Python使用 Elasticsearch DSL Python 的复合 Elasticsearch 聚合
【发布时间】:2019-05-21 14:06:51
【问题描述】:

我有以下查询在这里运行良好:

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

【问题讨论】:

    标签: python elasticsearch elasticsearch-dsl elasticsearch-dsl-py


    【解决方案1】:

    试试这样:

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

    更多信息可以找到here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 2015-06-05
      • 2019-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-21
      相关资源
      最近更新 更多