Query with multiple nested filter on same path not working


(vishee) #1

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


(system) #2

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