Hello everyone,
I have some trouble filtering on aggregated results although the post_filter is applied on the nested path. To give some context, I m aggregating on nested path aggregationTr.subField.countryId
using this query and including all results with the option min_doc_count : 0
:
Then I want to filter on aggregationTr.subField.parentZoneIds
but it doesn't seem to be working. any advice on that ?
"size":0,"_source":true,
"aggs":
{"nestedFlows":{"nested":{"path":"aggregationTr"},
"aggs":{"filters":
{"filter":
{"bool":{"must":[{"range":{"aggregationTr.date":{"gte":"2019-01-01T00:00:00.000Z","lte":"2019-03-31T23:59:59.999Z"}}},
{"term":{"aggregationTrades.direction":{"value":"import"}}},
{"terms":{"aggregationTr.subField.parentCountryId":[1,2,3,4]}},
"aggs":{
"granularity":
{"date_histogram":{"calendar_interval":"1M","order":{"_key":"asc"},"field":"aggregationTr.date", "min_doc_count":0, "extended_bounds":{"min":"2019-01-01T00:00:00.000Z","max":"2019-03-31T00:00:00.000Z"}
},
"aggs":{
"cargo-volume":{"sum":{"field":"aggregationTr.testField.volume"}},
"cargo-volume_gas":{"sum":{"field":"aggregationTr.testField.volume_gas"}}
"splitAgg":{
"terms":{"field":"aggregationTr.subField.countryId","missing":"0","size":300, "min_doc_count" : "0"},
"aggs":{"cargo-volume":{"sum":{"field":"aggregationTr.testField.volume", "missing":"0"}},
"cargo-volume_gas":{"sum":{"field":"aggregationTr.testField.volume_gas", "missing":"0"}}
}
}
}
}
}}
}}
},
"post_filter": {
"bool": {
"must": [ {
"nested":
{
"path": "aggregationTr",
"query": {
"bool": {
"must": [
{"terms":{"aggregationTr.subField.parentZoneIds":[1,2,3,4]}}
]
}
}
}
}
]}
}