# Mulitiple or loop with range

**URL:** <https://discuss.elastic.co/t/mulitiple-or-loop-with-range/74629>\
**Category:** Elasticsearch\
**Created:** [February 10, 2017, 9:57am UTC](https://discuss.elastic.co/t/mulitiple-or-loop-with-range/74629 "2017-02-10T09:57:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thanigaivelan19](https://avatars.discourse-cdn.com/v4/letter/t/90ced4/32.png) [@thanigaivelan19](https://discuss.elastic.co/u/thanigaivelan19)\
**Post date:** [February 10, 2017, 9:57am UTC](https://discuss.elastic.co/t/mulitiple-or-loop-with-range/74629/1 "2017-02-10T09:57:45Z")

</div>

Hi,

I want to fetch the data by product id and rating I had used below code for it , but it is not working, when i removed the rating range the code working fine.

I f i add the rating filter, i am getting unwanted result, showing some other product id also.

{  
"query": {  
"bool": {  
"should": [  
{  
"match": {  
"pid": "TC0000362"  
}  
},  
{  
"match": {  
"pid": "T0001999"  
}  
},  
{  
"match": {  
"pid": "TC0000363"  
}  
},  
{  
"match": {  
"pid": "TC0000538"  
}  
},  
{  
"match": {  
"pid": "TC0000550"  
}  
},  
{  
"match": {  
"pid": "TC0000551"  
}  
},  
{  
"match": {  
"pid": "TC0000554"  
}  
}  
],  
"filter": {  
"bool": {  
"must": {  
"range": {  
"rating": {  
"gte": 4.5  
}  
}  
}  
}  
}  
}  
}  
}

Please help me what mistake i am doing over here

Thanks

Thanigaivelan

---

<div class="post-metadata">

**Author:** ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)\
**Post date:** [February 10, 2017, 10:19am UTC](https://discuss.elastic.co/t/mulitiple-or-loop-with-range/74629/2 "2017-02-10T10:19:54Z")

</div>

The reason is this (from the [docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html)):

> In a boolean query with no must or filter clauses, one or more should clauses must match a document.

This means that when you add a filter, ES does not require any should clause to match, they're only used to rank the results in that case. You can change this by explicitly setting `"minimum_should_match" : 1`

---

<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:** [March 10, 2017, 10:20am UTC](https://discuss.elastic.co/t/mulitiple-or-loop-with-range/74629/3 "2017-03-10T10:20:04Z")

</div>

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