# OR'd Range Queries

**URL:** <https://discuss.elastic.co/t/ord-range-queries/5740>\
**Category:** Elasticsearch\
**Created:** [November 1, 2011, 9:34pm UTC](https://discuss.elastic.co/t/ord-range-queries/5740 "2011-11-01T21:34:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CliffB](https://avatars.discourse-cdn.com/v4/letter/c/ea5d25/32.png) [@CliffB](https://discuss.elastic.co/u/CliffB)\
**Post date:** [November 1, 2011, 9:34pm UTC](https://discuss.elastic.co/t/ord-range-queries/5740/1 "2011-11-01T21:34:44Z")

</div>

Just starting with ElasticSearch and am a bit tentative. Did study the  
guide, but have a few questions about what can get nested where, so please  
bear with me.

I need to AND numerous criteria (dynamically according to user entry). I  
presume that "must" under bool is like "and" under filter? If so, the  
example below will AND the elements of criteria:  
{  
"bool":  
{  
"must":[  
{"query\_string":  
{"query": "myStuff", "allow\_leading\_wildcard": true,  
"phrase\_slop": 0}  
},  
{"term": {"lastName":"Smith"}},  
{"range":{"age":{"from":"10", "to":"20"}}}  
]  
}  
}

The thing I would like to AND to the above structure is/are additional  
RANGE queries, which themselves have OR'd criteria. Can I effectively OR  
RANGE criteria like this?:  
{  
"range" : {  
"age" : {  
"from" : 10,  
"to" : 20  
}  
"age" : {  
"from" : 30,  
"to" : 40  
}  
}  
}  
Then AND that block to the "must" array in the 1st structure. Will  
ElasticSearch find indexes for multiple age ranges in this case from this  
syntax? Is there a better way? Thanks.

---

<div class="post-metadata">

**Author:** ![CliffB](https://avatars.discourse-cdn.com/v4/letter/c/ea5d25/32.png) [@CliffB](https://discuss.elastic.co/u/CliffB)\
**Post date:** [November 1, 2011, 9:43pm UTC](https://discuss.elastic.co/t/ord-range-queries/5740/2 "2011-11-01T21:43:32Z")

</div>

Oops on the 2nd JSON above. Obviously I can't have the \>1 age member in the  
same object. Is there a way to group multiple from/to criteria in [] under  
"age" so that it affect an OR'd search?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [November 1, 2011, 10:37pm UTC](https://discuss.elastic.co/t/ord-range-queries/5740/3 "2011-11-01T22:37:58Z")

</div>

Heya,

Yea, sure, you can do it. What you need in this case is to have another  
bool query for the range parts, with two should clauses. The range bool  
query will exists within the outer bool query (simply place it where the  
current range query is at).

On Tue, Nov 1, 2011 at 11:43 PM, CliffB [bentley.cliff@gmail.com](mailto:bentley.cliff@gmail.com) wrote:

> Oops on the 2nd JSON above. Obviously I can't have the \>1 age member in  
> the same object. Is there a way to group multiple from/to criteria in   
> under "age" so that it affect an OR'd search?

---

<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:50am UTC](https://discuss.elastic.co/t/ord-range-queries/5740/4 "2017-07-06T03:50:10Z")

</div>


