# Bool filter not matching on range query

**URL:** <https://discuss.elastic.co/t/bool-filter-not-matching-on-range-query/5188>\
**Category:** Elasticsearch\
**Created:** [August 17, 2011, 11:21pm UTC](https://discuss.elastic.co/t/bool-filter-not-matching-on-range-query/5188 "2011-08-17T23:21:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kikster](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kikster/32/3117_2.png) [@kikster](https://discuss.elastic.co/u/kikster)\
**Post date:** [August 17, 2011, 11:21pm UTC](https://discuss.elastic.co/t/bool-filter-not-matching-on-range-query/5188/1 "2011-08-17T23:21:49Z")

</div>

I'm submitting a filtered query with the following filter (I convert  
the hash into json before sending it)

```
        :filter => {
          :bool => {
            :must_not => {
              :term => {
                "show" => 0
              }
            },
            :must => {
              :range => {
                :price => {
                  :from => 0, :to => 20
                }
              }
            },
            :must => {
              :nested => {
                :path => "regions", :query => {
                  :term => {
                    "id" => var_1
                  }
                }
              }
            }
          }
        }

```

Documents get returned that meet all criteria except the "range" one.  
Do I have to do something special to match fields that have a number?  
Currently the "price" field is of type long....there's a snippet of  
the document's mapping below.

"price":{"type":"long"},

---

<div class="post-metadata">

**Author:** ![kikster](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kikster/32/3117_2.png) [@kikster](https://discuss.elastic.co/u/kikster)\
**Post date:** [August 18, 2011, 12:14am UTC](https://discuss.elastic.co/t/bool-filter-not-matching-on-range-query/5188/2 "2011-08-18T00:14:20Z")

</div>

Got it working with this exact same code. Not sure why it wasn't  
working before, but I'm positive it was something I was doing wrong.

On Aug 17, 4:21 pm, Chris [christopherdavidoliva...@gmail.com](mailto:christopherdavidoliva...@gmail.com) wrote:

> I'm submitting a filtered query with the following filter (I convert  
> the hash into json before sending it)
> 
> ```
> :filter => {
> :bool => {
> :must_not => {
> :term => {
> "show" => 0
> }
> },
> :must => {
> :range => {
> :price => {
> :from => 0, :to => 20
> }
> }
> },
> :must => {
> :nested => {
> :path => "regions", :query => {
> :term => {
> "id" => var_1
> }
> }
> }
> }
> }
> }
> 
> ```
> 
> Documents get returned that meet all criteria except the "range" one.  
> Do I have to do something special to match fields that have a number?  
> Currently the "price" field is of type long....there's a snippet of  
> the document's mapping below.
> 
> "price":{"type":"long"},

---

<div class="post-metadata">

**Author:** ![kikster](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kikster/32/3117_2.png) [@kikster](https://discuss.elastic.co/u/kikster)\
**Post date:** [August 18, 2011, 12:51am UTC](https://discuss.elastic.co/t/bool-filter-not-matching-on-range-query/5188/3 "2011-08-18T00:51:20Z")

</div>

Also, what's weird is that a query that uses the exact same filter,  
but omits the "nested" query works. Now I'm starting to think it has  
something to do with having multiple bool "must" clauses in a bool  
query. Why would including the last must clause cause the query to no  
longer match on a price range?

On Aug 17, 4:21 pm, Chris [christopherdavidoliva...@gmail.com](mailto:christopherdavidoliva...@gmail.com) wrote:

> I'm submitting a filtered query with the following filter (I convert  
> the hash into json before sending it)
> 
> ```
> :filter => {
> :bool => {
> :must_not => {
> :term => {
> "show" => 0
> }
> },
> :must => {
> :range => {
> :price => {
> :from => 0, :to => 20
> }
> }
> },
> :must => {
> :nested => {
> :path => "regions", :query => {
> :term => {
> "id" => var_1
> }
> }
> }
> }
> }
> }
> 
> ```
> 
> Documents get returned that meet all criteria except the "range" one.  
> Do I have to do something special to match fields that have a number?  
> Currently the "price" field is of type long....there's a snippet of  
> the document's mapping below.
> 
> "price":{"type":"long"},

---

<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:** [July 6, 2017, 3:56am UTC](https://discuss.elastic.co/t/bool-filter-not-matching-on-range-query/5188/4 "2017-07-06T03:56:44Z")

</div>


