我有一个索引,名字叫stat 是嵌套文档mapping如下
那么现在有个问题。
如果按照date_histogram来按照日期计算退款完成的(refundtime不是0的)那么dsl如下:
问题:
我要如何处理这种情况的统计,需要怎么写或者怎么去改变mapping结构
尝试过filter,post_filter,nested 貌似都不行~
感谢!
{
"stat": {
"mappings": {
"properties": {
"orderParent": {
"properties": {
"createTime": {
"type": "date"
},
"orderAmount": {
"type": "float"
},
"sendTime": {
"type": "date"
}
}
},
"orderRefund": {
"properties": {
"refundTime": {
"type": "date"
},
"refundMoney": {
"type": "float"
},
"goodsId": {
"type": "long"
},
"brandId": {
"type": "long"
}
}
}
}
}
}
}
可插入数据如下:{
"orderParent": {
"createTime": 1640054394,
"orderAmount": 1893.62,
"sendTime": 0
},
"orderRefund": [
{
"refundTime": 1640054394,
"refundMoney": 66.88,
"brandId": 33322,
"goodsId": 2323
},
{
"refundTime": 0,
"refundMoney": 122.88,
"brandId": 9988,
"goodsId": 2111
}
]
}
那么现在有个问题。
如果按照date_histogram来按照日期计算退款完成的(refundtime不是0的)那么dsl如下:
{
"size": 0,
"aggs": {
"filter_done": {
"filter": {
"bool": {
"must_not": [
{
"term": {
"orderRefund.refundTime": 0
}
}
]
}
},
"aggs": {
"histogram_orderRefund_refundTime": {
"date_histogram": {
"field": "orderRefund.refundTime",
"calendar_interval": "year",
"time_zone": "Asia/Shanghai"
},
"aggs": {
"sub_sum_orderRefund_refundMoney": {
"sum": {
"field": "orderRefund.refundMoney"
}
}
}
}
}
}
}
}
即使改成aggs中写上filter出来的结果还是orderRefund中两组数据的 refundMoney相加的~。问题:
我要如何处理这种情况的统计,需要怎么写或者怎么去改变mapping结构
尝试过filter,post_filter,nested 貌似都不行~
感谢!
3 个回复
Ombres
赞同来自: Jea
God_lockin
赞同来自:
Jea - 一只猿
赞同来自: