弹性搜索累计值的SUM [英] Elastic Search SUM of aggregated values

查看:119
本文介绍了弹性搜索累计值的SUM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用弹性搜索来获得一些静态。


  1. 我需要获取每个组的平均值。

  2. 将所有这些值归纳

到目前为止,步骤号。 1很简单。但是,我真的不知道如何总结所有的价值观。这可能吗?如果是,怎么样?。



感谢您的建议。
这是我的搜索查询>

  {
查询:{
过滤:{
query:{
query_string:{
analyze_wildcard:true,
query:*
}

}
},
aggs:{
2:{
terms:{
field:person ,
size:5000,
order:{
1:desc
}
},
aggs :{
1:{
avg:{
field:company
}
}
}

}
}


解决方案

聚合结果的聚合在弹性搜索中尚未得到支持。显然,正在为2.0开发的概念叫做 reducers 。我建议看看脚本度量聚合。基本上,您可以通过使用脚本控制收集和计算方面来创建自己的聚合。



或者,如果可能,您可以预先计算并存储索引时的平均值,然后使用查询时的汇总。



有关此聚合的示例,请查看以下问题:弹性搜索:可以处理聚合结果?


We are using elastic search to get some statics.

  1. I need to get average values for each group.
  2. Sum all this values

So far, step no. 1 was pretty straight forward. However I really don't know how to sum all values at the end. Is this possible? If yes, how?.

Thanks for suggestions. Here is my aggs query >

{  
   "query":{  
      "filtered":{  
         "query":{  
            "query_string":{  
               "analyze_wildcard":true,
               "query":"*"
            }
         }
      }
   },
   "aggs":{  
      "2":{  
         "terms":{  
            "field":"person",
            "size":5000,
            "order":{  
               "1":"desc"
            }
         },
         "aggs":{  
            "1":{  
               "avg":{  
                  "field":"company"
               }
            }
         }
      }
   }
}

解决方案

Aggregating over aggregation results are not yet supported in elasticsearch. Apparently there is a concept called reducers that are being developed for 2.0. I would suggest having a look at scripted metric aggregations. Basically, you can create your own aggregation by controlling the collection and computation aspects yourself using scripts.

Alternatively, if possible you can precompute and store the average when indexing and then use the sum aggregation when querying.

Have a look at the following question for an example of this aggregation: Elasticsearch: Possible to process aggregation results?

这篇关于弹性搜索累计值的SUM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆