# Multiple Range filter query

**URL:** <https://discuss.elastic.co/t/multiple-range-filter-query/11708>\
**Category:** Elasticsearch\
**Created:** [April 26, 2013, 6:22pm UTC](https://discuss.elastic.co/t/multiple-range-filter-query/11708 "2013-04-26T18:22:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yree](https://avatars.discourse-cdn.com/v4/letter/y/90ced4/32.png) [@yree](https://discuss.elastic.co/u/yree)\
**Post date:** [April 26, 2013, 6:22pm UTC](https://discuss.elastic.co/t/multiple-range-filter-query/11708/1 "2013-04-26T18:22:22Z")

</div>

Hi,

I can create the facet for the ranges. But if I select more than one facet I want to be able to  
filter on it with OR filter which doesn't seem to give me correct results.

The count for vehicles between 1995 to 2000 = 661  
The count for vehicles between 2000 to 2005 = 837

When I execute below query it returns 1367 results. It should have returned 661+837=1498 results?

{  
"query": {  
"filtered": {  
"query": {  
"bool": {  
"must": [  
{  
"term": {  
"vehicle.entityType": "vehicle"  
}  
}  
]  
}  
},  
"filter": {  
"or": [  
{  
"range": {  
"vehicleYear": {  
"from": 1995,  
"to": 2000  
}  
}  
},  
{  
"range": {  
"vehicleYear": {  
"from": 2000,  
"to": 2005  
}  
}  
}  
]  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [April 28, 2013, 2:21am UTC](https://discuss.elastic.co/t/multiple-range-filter-query/11708/2 "2013-04-28T02:21:07Z")

</div>

The from and to values of a range filter are inclusive, so both clauses of  
the range filter will match vehicles from the year 2000 and the duplicates  
are omitted. Judging by your results, 131 vehicles are from 2000.

For better performance, you can use a match all query and move your term  
query into the filter section.

--  
Ivan

On Fri, Apr 26, 2013 at 11:22 AM, yree [yashashree.lad@gmail.com](mailto:yashashree.lad@gmail.com) wrote:

> Hi,
> 
> I can create the facet for the ranges. But if I select more than one facet  
> I  
> want to be able to  
> filter on it with OR filter which doesn't seem to give me correct results.
> 
> The count for vehicles between 1995 to 2000 = 661  
> The count for vehicles between 2000 to 2005 = 837
> 
> When I execute below query it returns 1367 results. It should have returned  
> 661+837=1498 results?
> 
> {  
> "query": {  
> "filtered": {  
> "query": {  
> "bool": {  
> "must": [  
> {  
> "term": {  
> "vehicle.entityType": "vehicle"  
> }  
> }  
> ]  
> }  
> },  
> "filter": {  
> "or": [  
> {  
> "range": {  
> "vehicleYear": {  
> "from": 1995,  
> "to": 2000  
> }  
> }  
> },  
> {  
> "range": {  
> "vehicleYear": {  
> "from": 2000,  
> "to": 2005  
> }  
> }  
> }  
> ]  
> }  
> }  
> }  
> }
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Multiple-Range-filter-query-tp4033894.html](http://elasticsearch-users.115913.n3.nabble.com/Multiple-Range-filter-query-tp4033894.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![yree](https://avatars.discourse-cdn.com/v4/letter/y/90ced4/32.png) [@yree](https://discuss.elastic.co/u/yree)\
**Post date:** [April 30, 2013, 10:10pm UTC](https://discuss.elastic.co/t/multiple-range-filter-query/11708/3 "2013-04-30T22:10:52Z")

</div>

Thanks so much for your response. It worked when I included lower value and  
made include upper -false. The counts matched!

On Sat, Apr 27, 2013 at 7:21 PM, Ivan Brusic [via Elasticsearch Users] \<  
[ml-node+s115913n4033921h73@n3.nabble.com](mailto:ml-node+s115913n4033921h73@n3.nabble.com)\> wrote:

> The from and to values of a range filter are inclusive, so both clauses of  
> the range filter will match vehicles from the year 2000 and the duplicates  
> are omitted. Judging by your results, 131 vehicles are from 2000.
> 
> For better performance, you can use a match all query and move your term  
> query into the filter section.
> 
> --  
> Ivan
> 
> On Fri, Apr 26, 2013 at 11:22 AM, yree \<[hidden email][http://user/SendEmail.jtp?type=node&node=4033921&i=0](http://user/SendEmail.jtp?type=node&node=4033921&i=0)
> 
> > wrote:
> 
> > Hi,
> > 
> > I can create the facet for the ranges. But if I select more than one  
> > facet I  
> > want to be able to  
> > filter on it with OR filter which doesn't seem to give me correct results.
> > 
> > The count for vehicles between 1995 to 2000 = 661  
> > The count for vehicles between 2000 to 2005 = 837
> > 
> > When I execute below query it returns 1367 results. It should have  
> > returned  
> > 661+837=1498 results?
> > 
> > {  
> > "query": {  
> > "filtered": {  
> > "query": {  
> > "bool": {  
> > "must": [  
> > {  
> > "term": {  
> > "vehicle.entityType": "vehicle"  
> > }  
> > }  
> > ]  
> > }  
> > },  
> > "filter": {  
> > "or": [  
> > {  
> > "range": {  
> > "vehicleYear": {  
> > "from": 1995,  
> > "to": 2000  
> > }  
> > }  
> > },  
> > {  
> > "range": {  
> > "vehicleYear": {  
> > "from": 2000,  
> > "to": 2005  
> > }  
> > }  
> > }  
> > ]  
> > }  
> > }  
> > }  
> > }
> > 
> > --  
> > View this message in context:  
> > [http://elasticsearch-users.115913.n3.nabble.com/Multiple-Range-filter-query-tp4033894.html](http://elasticsearch-users.115913.n3.nabble.com/Multiple-Range-filter-query-tp4033894.html)  
> > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [hidden email][http://user/SendEmail.jtp?type=node&node=4033921&i=1](http://user/SendEmail.jtp?type=node&node=4033921&i=1)  
> > .  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [hidden email][http://user/SendEmail.jtp?type=node&node=4033921&i=2](http://user/SendEmail.jtp?type=node&node=4033921&i=2)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> * * *
> 
> If you reply to this email, your message will be added to the discussion  
> below:
> 
> [http://elasticsearch-users.115913.n3.nabble.com/Multiple-Range-filter-query-tp4033894p4033921.html](http://elasticsearch-users.115913.n3.nabble.com/Multiple-Range-filter-query-tp4033894p4033921.html)  
> To unsubscribe from Multiple Range filter query, click here[http://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe\_by\_code&node=4033894&code=eWFzaGFzaHJlZS5sYWRAZ21haWwuY29tfDQwMzM4OTR8LTEzMjcwOTk5OQ==](http://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4033894&code=eWFzaGFzaHJlZS5sYWRAZ21haWwuY29tfDQwMzM4OTR8LTEzMjcwOTk5OQ==)  
> .  
> NAML[http://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=macro\_viewer&id=instant\_html!nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify\_subscribers!nabble%3Aemail.naml-instant\_emails!nabble%3Aemail.naml-send\_instant\_email!nabble%3Aemail.naml](http://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml)

---

<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, 2:39am UTC](https://discuss.elastic.co/t/multiple-range-filter-query/11708/4 "2017-07-06T02:39:00Z")

</div>


