数据如下 kibana,elasticsearch 6.5.0
{
"id" : 1,
"ordersStatus" : 1,
"incomeList" : [
{
"memberId" : 2,
"incomeType" : 1,
"incomeAmount" : 0.2
},
{
"memberId" : 3,
"incomeType" : 1,
"incomeAmount" : 0.3
}
]
}
搜索语句如下
{
"query": {
"bool": {
"must": [
{
"term": {
"ordersStatus": {
"value": 1
}
}
},
{
"term": {
"incomeList.memberId": {
"value": 2
}
}
}
]
}
},
"aggs": {
"by_memberId": {
"terms": {
"field": "incomeList.memberId"
},
"aggs": {
"do_a_sum": {
"sum": {
"field": "incomeList.incomeAmount"
}
}
}
}
}
}
获得结果如下
"aggregations" : {
"by_memberId" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : 2,
"doc_count" : 1,
"do_a_sum" : {
"value" : 0.5
}
},
{
"key" : 3,
"doc_count" : 1,
"do_a_sum" : {
"value" : 0.5
}
}
]
}
}
我期望的结果是 只有对应memberId = 2,取得do_a_sum {value:0.2} ,请问有什么优化的意见吗
1 个回复
FFFrp
赞同来自: yangcj