【问题标题】:ElasticSearch: get the bucket key inside bucket scripted_metricElasticSearch:获取存储桶 scripted_metric 中的存储桶键
【发布时间】:2017-10-11 14:20:59
【问题描述】:

我正在尝试在 elasticsearch 中运行此查询。我试图在我的存储桶上运行自定义 scripted_metric 聚合。在指标脚本中,我想访问聚合它的存储桶键。

我在 ES 中的文档是这样的。

{
    user_id: 5,
    data: {
        5: 200,
        8: 300
    }
},
{
    user_id: 8,
    data: {
        5: 889,
        8: 22
    }
}

我的聚合查询如下所示:

aggs = {
    approvers: {
        terms: {
            field: 'user_id'
        },
        aggs: {
            new_metric: {
                scripted_metric: {
                    map_script: `
                        // IS IT POSSIBLE TO GET THE BUCKET KEY HERE?
                        // The bucket key here would be the user_id
                        // so i can do stuff like

                        doc['data'][**_term**]....
                    `
                }
            }
        }
}

【问题讨论】:

  • 你解决过这个问题吗?

标签: elasticsearch


【解决方案1】:

我不得不进行一些挖掘,并且在寻找如何检索父值的解决方案时可能遇到同样的困难......我唯一能找到的是关于一个特殊的“_count”值子 agg,但与它的父存储桶名称/键无关。

如果使用带有 scripted_metric 的子 agg 不是严格要求,我能够找到一种方法,让您至少可以访问父母中的存储桶密钥。也许这可以让您开始寻找解决方案:

aggs = {
    approvers: {
        terms: {
            field: 'user_id',
            script: '"There seems to be a magic value here: " + _value'
        }
}

样本改编自this

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-22
    • 2021-08-02
    • 1970-01-01
    • 2020-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多