【问题标题】:Elastic Search bucket script for percentile aggregated values用于百分位聚合值的 Elastic Search 存储桶脚本
【发布时间】:2019-01-29 16:27:08
【问题描述】:

以下是我的问题陈述 我有一个对弹性搜索的搜索调用,该调用具有计算其中一个字段的 99% 百分位数聚合的查询。作为回报,我得到聚合响应,其值是百分位数计算的。但我再次需要对百分位聚合值应用过滤器,使用“bucket_selector”过滤掉这些值。例如,如果百分位聚合值 > 60,那么我需要将其包含在我的回复中。 以下是我的示例聚合请求 json:

        {
      "aggs": {
        "2": {
           "terms": {
           "field": "component",
           "size": 500,
           "order": {
           "1": "desc"
          }
         },
         "aggs": {
              "1": {
                   "percentiles": {
                       "field": "field1",
                        "percents": [
                            99
                         ],
                  "keyed": false
                   }
              },
        "filter_gt_than_60sec": {
          "bucket_selector": {
            "buckets_path": {
              "value": "1"
            },
            "script": "params.value > 60L"
          }
        }
      }
      }
     },
      "size": 0,
      "_source": {
        "excludes": []
      },
      "stored_fields": [
        "*"
      ],
      "script_fields": {},
      "query": {
        "bool": {
          "must": [
            {
              "match_all": {}
            },
            {
              "range": {
                "@timestamp": {
                  "gte": 1547889125683,
                  "lte": 1547975525684,
                  "format": "epoch_millis"
                }
              }
            }
          ],
          "filter": [],
          "should": [],
          "must_not": []
        }
      },
      "timeout": "30000ms"
     }

我得到的错误:

        {
            "error": {
                "root_cause": [],
                "type": "search_phase_execution_exception",
                "reason": "",
                "phase": "fetch",
                "grouped": true,
                "failed_shards": [],
                "caused_by": {
                    "type": "aggregation_execution_exception",
                    "reason": "buckets_path must reference either a number value or a single value numeric metric aggregation, got: org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.InternalTDigestPercentiles"
                }
            },
            "status": 503
        }

如果没有应用存储桶选择器,则示例响应映射文档:

    {
      "aggregations": {
        "2": {
          "doc_count_error_upper_bound": 0,
          "sum_other_doc_count": 0,
          "buckets": [
            {
              "1": {
                "values": [
                  {
                    "key": 99,
                    "value": 70
                  }
                ]
              },
              "key": "abc"
            },
            {
              "1": {
                "values": [
                  {
                    "key": 99,
                    "value": 10
                  }
                ]
              },
            "key": "abc1"
        }
        ]
    }}}

我从上面的错误中了解到,我不能在百分位字段上应用“bucket_selector”,那么我该如何过滤掉值大于 60 的百分位聚合字段。我读到了“percentile_bucket”,但它是计算字段值的百分位数;但它没有过滤掉聚合的百分位数字段。提前致谢。

【问题讨论】:

  • 您的映射是什么样的?也许还发布一个示例文档
  • 您好,感谢您的回复。如果我们不应用 bucket_selectors 过滤值,我会使用响应映射文档更新上述查询。

标签: elasticsearch elasticsearch-aggregation


【解决方案1】:

谢谢,问题现已解决,并且可以通过将当前发布请求替换为以下 buckets_path 代码来访问百分位值字段:

       "bucket_selector": {
        "buckets_path": {
          "value": "1[99.0]"
        },
        "script": "params.value > 60L"
      }

【讨论】:

  • 太棒了,帮了很多忙
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-14
  • 2016-02-06
  • 2015-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-29
相关资源
最近更新 更多