【问题标题】:Can We Apply Bucket Selector Aggregation on Nested Aggregation in ElasticSearch?我们可以在 ElasticSearch 中的嵌套聚合上应用桶选择器聚合吗?
【发布时间】:2018-02-05 17:38:59
【问题描述】:

我想在 ElasticSearch 2.4 中使用管道聚合(桶选择器聚合)到嵌套字段聚合。我想做类似于下面的事情,但我没有成功。如果可以在嵌套字段中进行管道聚合,您能否建议我?

 {
  "size": 0,
  "aggregations": {
    "totalPaidAmount": {
      "nested": {
        "path": "count"
      },
      "aggregations": {
        "paidAmountTotal": {
          "sum": {
            "field": "count.totalPaidAmount"
          }
        },
        "paidAmount_filter": {
          "bucket_selector": {
            "script": {
              "inline": "amount > 5000000"
            },
            "buckets_path": {
              "amount": "paidAmountTotal"
            }
          }
        }
      }
    }
  }
}

【问题讨论】:

    标签: elasticsearch lucene


    【解决方案1】:

    我找到了查询的解决方案。实际上,桶选择器聚合应该与嵌套聚合并行,路径应该由'>'引用,如下所示:

    {
      "size": 0,
      "aggregations": {
        "amount": {
          "terms": {
            "field": "countId",
            "size": 0
          },
          "aggregations": {
            "totalPaidAmount": {
              "nested": {
                "path": "count"
              },
              "aggregations": {
                "paidAmountTotal": {
                  "sum": {
                    "field": "count.totalPaidAmount"
                  }
                }
              }
            },
            "paidAmount_filter": {
              "bucket_selector": {
                "script": {
                  "inline": "amount > 1000"
                },
                "buckets_path": {
                  "amount": "totalPaidAmount>paidAmountTotal"
                }
              }
            }
          }
        }
      }
    }
    

    【讨论】:

      【解决方案2】:

      script 值中缺少 params。所以,paidAmount_filter 应该是这样的:

      "bucket_filter": {
        "bucket_selector": {
          "buckets_path": {
            "amount ": "paidAmountTotal"
          },
          "script": "params.amount > 5000000"
        }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-04-15
        • 2021-12-14
        • 2015-11-18
        • 1970-01-01
        • 2023-03-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多