# Post\_filter on aggregated results

**URL:** <https://discuss.elastic.co/t/post-filter-on-aggregated-results/314671>\
**Category:** Elasticsearch\
**Created:** [September 19, 2022, 7:58am UTC](https://discuss.elastic.co/t/post-filter-on-aggregated-results/314671 "2022-09-19T07:58:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emna\_Jaoua](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emna_jaoua/32/110281_2.png) [@Emna\_Jaoua](https://discuss.elastic.co/u/Emna_Jaoua)\
**Post date:** [September 19, 2022, 7:58am UTC](https://discuss.elastic.co/t/post-filter-on-aggregated-results/314671/1 "2022-09-19T07:58:18Z")

</div>

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 ?

```auto
"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]}}
                                ]
                            }
                        }
                       }
                     }
            ]}
  }

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 17, 2022, 7:59am UTC](https://discuss.elastic.co/t/post-filter-on-aggregated-results/314671/2 "2022-10-17T07:59:09Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
