这是我们的工作。你可以用过滤部分的脚本创建total nb条件,但它会非常慢。
{
"size": 0,
"query" : {
"nested" : {
"path" : "categories",
"query" : {
"bool" : {
"must" : [
{
"term" : {"categories.origin" : "bbbb"}
},
{
"range" : {"categories.nb_items" : {"gt" : 4}}
}
]}
}
}
},
"aggregations": {
"totalnbbydoc": {
"terms": {
"field": "youriddoc",
"size": 10000
},
"aggregations": {
"totalByNested": {
"nested": {
"path": "categories"
},
"aggregations": {
"nbtotal": {
"sum": {
"field": "categories.nb_items"
}
}
}
},
"paidAmount_filter": {
"bucket_selector": {
"script": {
"inline": "params.totalnbbydoc > 10"
},
"buckets_path": {
"totalnbbydoc": "totalByNested>nbtotal"
}
}
}
}
}
}
}