I just started working with ES I am facing an issue with the query body I need to filter results using two fields, price and discount. It works fine when I use them with must but some of the documents do not contain a discount field. how to get those too. I am confused about how to write the query. below is what I am using currently. It returns the response without discount but does not apply a range filter. Please help me to fix this issue and explain how it works.
"bool": {
      "filter": [
        {
            "bool": {
                "should": [
                   {
                   "range": {
                      "discount": {
                            "gte": $minDiscount,
                            "lte": $maxDiscount
                            }
                        }
                    }
                ],
                "must":[
                    {
                    "range": {
                       "price": {
                            "gte": $minPrice,
                            "lte": $maxPrice
                             }
                          }
                      }
                ]
            }
        },
       ]
     }