elasticSearch 怎么按字段中的类型聚合
本文介绍了elasticSearch 怎么按字段中的类型聚合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
如题。如果有一个type字段,可能值是apple, orange, banana等等,不确定有几个类型。有一个字段是销售额。现在希望做一个按type聚合,再求销售总额。也就是希望按分类求和。
这个问题已被关闭,原因:问题已解决 - 问题已解决,且对他人无借鉴意义
解决方案
curl -XPOST 'localhost:9200/sales/_search?size=0&pretty' -H 'Content-Type: application/json' -d'
{
...,
"aggs": {
"by_type": {
"terms": {"field": "type"},
"aggs": {
"amount_sum": {
"sum" : {"field" : "amount"}
}
}
}
}
}
'
参见:
https://www.elastic.co/guide/...
https://www.elastic.co/guide/...
https://stackoverflow.com/que...
这篇关于elasticSearch 怎么按字段中的类型聚合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文