【问题标题】:Elastic Search, use scripted field for an aggregation result弹性搜索,使用脚本字段获取聚合结果
【发布时间】:2020-04-07 16:08:04
【问题描述】:

我想知道是否可以在聚合结果中包含scripted_field

示例查询:

GET /index/_search
{
  "query": {
    "match_all": {}
  },
  "agg": {
    "test": {
      "terms": {
        "field": "key"
      }
    }
  }
}

我要归档的结果如下:

{
    "aggregations": {
        "test": {
            "buckets": [
                {
                    "key": "key1",
                    "doc_count": 10,
                    "new value": // can be filled via a plainless script.
                }
            ]
        }
    }
}

【问题讨论】:

    标签: elasticsearch elasticsearch-painless


    【解决方案1】:

    不,无法从聚合中访问脚本化字段,因为它们构成单独的上下文/parts of the API

    您可以改用script terms aggregations(您最有可能在寻找)或scripted metric aggregations


    编辑

    您无法修改响应的结构/语法,但您可以拥有全局共享的 agg metadata。如果您需要更多信息,请使用具体用例、映射和数据来阐述您的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-19
      • 1970-01-01
      • 2015-07-25
      • 1970-01-01
      相关资源
      最近更新 更多