问题
I am using composite aggregation on nested fields in elasticsearch but I want to exclude some terms from the result.
This aggregation is working:
{
"size": 0,
"geo": {
"communication": {
"nested": {
"path": "geo"
},
"aggs": {
"table": {
"composite": {
"size": 1000,
"sources": [
{"stk1": {"terms": {"field": "geo.src"}}},
{"stk2": {"terms": {"field": "geo.dest"}}}
]
}
}
}
}
}
}
But I want to exclude some terms from stk2,
{
"size": 0,
"aggs": {
"geo": {
"nested": {
"path": "geo"
},
"aggs": {
"table": {
"composite": {
"size": 1000,
"sources": [
{"stk1": {"terms": {"field": "geo.src"}}},
{"stk2": {"terms": {"field": "geo.dest", "exclude":"cancel"}}}
]
}
}
}
}
}
}
The above query is not working.
UPDATE 1: The result should omit only the array elements and not the entire document containing "cancel".
I am using elastic v6.7
回答1:
I'd suggest using a query to exclude those documents:
{
"size": 0,
"aggs": {
"geo": {
"nested": {
"path": "geo"
}
},
"aggs": {
"filter": {
"bool": {
"must_not": {
"prefix": {
"geo.dest": "cancel"
}
}
}
},
"aggs": {
"table": {
"composite": {
"size": 10,
"sources": [
{
"stk1": {
"terms": {
"field": "geo.src"
}
}
},
{
"stk2": {
"terms": {
"field": "geo.dest"
}
}
}
]
}
}
}
}
}
}
来源:https://stackoverflow.com/questions/56059780/how-to-exclude-terms-in-nested-composite-aggregation