# Query with multiple nested filter on same path not working

**URL:** <https://discuss.elastic.co/t/query-with-multiple-nested-filter-on-same-path-not-working/98489>\
**Category:** Elasticsearch\
**Created:** [August 27, 2017, 9:21pm UTC](https://discuss.elastic.co/t/query-with-multiple-nested-filter-on-same-path-not-working/98489 "2017-08-27T21:21:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishee](https://avatars.discourse-cdn.com/v4/letter/v/f0a364/32.png) [@vishee](https://discuss.elastic.co/u/vishee)\
**Post date:** [August 27, 2017, 9:21pm UTC](https://discuss.elastic.co/t/query-with-multiple-nested-filter-on-same-path-not-working/98489/1 "2017-08-27T21:21:23Z")

</div>

I have a query where there are 2 nested filters as follows (generated via Java API):

```
GET pay/_search
{
  "size" : 1000,
  "query" : {
    "bool" : {
      "filter" : [
        {
          "bool" : {
            "must" : [

              {
                "nested" : {
                  "query" : {
                    "bool" : {
                      "must" : [
                        {
                          "match" : {
                            "paySerieAccu.accuId" : {
                              "query" : "PeriodEmployerTaxesAndCosts",
                              "operator" : "OR",
                              "prefix_length" : 0,
                              "max_expansions" : 50,
                              "fuzzy_transpositions" : true,
                              "lenient" : false,
                              "zero_terms_query" : "NONE",
                              "boost" : 1.0
                            }
                          }
                        },
                        {
                          "range" : {
                            "paySerieAccu.amount" : {
                              "from" : 50000,
                              "to" : null,
                              "include_lower" : false,
                              "include_upper" : true,
                              "boost" : 1.0
                            }
                          }
                        }
                      ],
                      "disable_coord" : false,
                      "adjust_pure_negative" : true,
                      "boost" : 1.0
                    }
                  },
                  "path" : "paySerieAccu",
                  "ignore_unmapped" : false,
                  "score_mode" : "none",
                  "boost" : 1.0,
                  "inner_hits" : {
                    "name" : "paySerieAccu",
                    "ignore_unmapped" : true,
                    "from" : 0,
                    "size" : 1000,
                    "version" : false,
                    "explain" : false,
                    "track_scores" : false
                  }
                }
              },
              {
                "nested" : {
                  "query" : {
                    "bool" : {
                      "must" : [
                        {
                          "match" : {
                            "paySerieAccu.accuId" : {
                              "query" : "PeriodGrossSalary",
                              "operator" : "OR",
                              "prefix_length" : 0,
                              "max_expansions" : 50,
                              "fuzzy_transpositions" : true,
                              "lenient" : false,
                              "zero_terms_query" : "NONE",
                              "boost" : 1.0
                            }
                          }
                        },
                        {
                          "range" : {
                            "paySerieAccu.amount" : {
                              "from" : 100000,
                              "to" : null,
                              "include_lower" : false,
                              "include_upper" : true,
                              "boost" : 1.0
                            }
                          }
                        }
                      ],
                      "disable_coord" : false,
                      "adjust_pure_negative" : true,
                      "boost" : 1.0
                    }
                  },
                  "path" : "paySerieAccu",
                  "ignore_unmapped" : false,
                  "score_mode" : "none",
                  "boost" : 1.0,
                  "inner_hits" : {
                    "name" : "paySerieAccu",
                    "ignore_unmapped" : true,
                    "from" : 0,
                    "size" : 1000,
                    "version" : false,
                    "explain" : false,
                    "track_scores" : false
                  }
                }
              }
            ],
            "disable_coord" : false,
            "adjust_pure_negative" : true,
            "boost" : 1.0
          }
        }
      ],
      "disable_coord" : false,
      "adjust_pure_negative" : true,
      "boost" : 1.0
    }
  },
  "_source" : {
    "includes" : [
      "inner_hits"
    ],
    "excludes" : []
  },
  "sort" : [
    {
      "paySerieAccu.accuId" : {
        "order" : "desc"
      }
    }
  ]
}

```

Note that these nested filters are for the same path and their fields queried are the same.  
However, when I get the results, I can see that filtering is done on the last nested filter only.  
I don't understand why there are no results for the first nested filter even if they exists.

Thanks for helping

---

<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:** [September 24, 2017, 9:21pm UTC](https://discuss.elastic.co/t/query-with-multiple-nested-filter-on-same-path-not-working/98489/2 "2017-09-24T21:21:42Z")

</div>

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