Raghu K Nair
Raghu K Nair

Reputation: 3942

Combining missing term filter and range check in elastic search

I get zero result when combining range filter and missing filter together in a query. Query is given below. I get this issue only while combining missing and range individually both works good. Any help is appreciated on correcting the query or the code. I am elastic search 1.7.3 version.

 {
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "bool": {
          "must": [
            {
              "bool": {
                "should": {
                  "missing": {
                    "field": "OrderData.XXXX.XXXXQueue"
                  }
                }
              }
            },
            {
              "range": {
                "OrderData.XXXX.priority": {
                  "from": 1,
                  "to": 5,
                  "include_lower": true,
                  "include_upper": true
                }
              }
            }
          ]
        }
      }
    }
  }
}

Upvotes: 0

Views: 381

Answers (1)

scottjustin5000
scottjustin5000

Reputation: 1346

Does this Query get you the expected results?

 {
      "query": {
        "filtered": {
          "query": {
            "match_all": {}
          },
          "filter": {
            "bool": {
              "must": {
                "bool": {
                  "should": [{
                    "missing": {
                      "field": "OrderData.XXXX.XXXXQueue"
                    }
                  }, {
                    "range": {
                      "OrderData.XXXX.priority": {
                        "from": 1,
                        "to": 5,
                        "include_lower": true,
                        "include_upper": true
                      }
                    }
                  }]
                }
              }
            }
          }
        }
      }
    }

Upvotes: 1

Related Questions