2
例如,我的映射具有一个属性“itemDetails”,类似这样的和聚集elasticsearch
{
"properties":{
"itemDetails":{
"properties":{
"id1":{"type": "long"},
"iddetailCode1": {"type": "string"},
"id2":{"type": "long"},
"iddetailCode2": {"type": "string"},
"amount": {"type": "double"}
}
}
}
}
和一个项目,它有多个记录。我想通过iddetailCode1进行分组,并总结所有的数量。但是,如果两个rocords数量相同,则只计算一次,我无法获得正确的数据。
我的查询是这样的。
{
"aggs": {
"user_likes": {
"terms": {
"field": "itemDetails.entityDetailCode1"
},
"aggs": {
"likes_sum": {
"sum": {
"field": "itemDetails.amount"
}
}
}
}
}
}
聚集条款每创造独特的价值一个桶,并在这些桶的数不是100%准确。 https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html – Gavin
谢谢加文,是的,这就是为什么最后我使用嵌套聚合,可以给我们准确的结果。 – Kazehaya