# Problem with multiple range in nested

**URL:** <https://discuss.elastic.co/t/problem-with-multiple-range-in-nested/11210>\
**Category:** Elasticsearch\
**Created:** [March 19, 2013, 5:30pm UTC](https://discuss.elastic.co/t/problem-with-multiple-range-in-nested/11210 "2013-03-19T17:30:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabien\_Guiraud](https://avatars.discourse-cdn.com/v4/letter/f/57b2e6/32.png) [@Fabien\_Guiraud](https://discuss.elastic.co/u/Fabien_Guiraud)\
**Post date:** [March 19, 2013, 5:30pm UTC](https://discuss.elastic.co/t/problem-with-multiple-range-in-nested/11210/1 "2013-03-19T17:30:41Z")

</div>

Hi,

I do that request :

curl -X GET  
'[http://78.109.90.3:9200/users/user/\_search?from=0&load=&size=20&pretty](http://78.109.90.3:9200/users/user/_search?from=0&load=&size=20&pretty)' -d  
'{  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"and": [{  
"nested": {  
"path": "apps\_events",  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"and": [{  
"term": {  
"apps\_events.status": "active"  
}  
}, {  
"or": [{  
"and": [{  
"range": {

"apps\_events.locations.inf": {  
"gte": 59850  
}  
}  
}, {  
"range": {

"apps\_events.locations.sup": {  
"lte": 59851  
}  
}  
}]  
}]  
}]  
}  
}  
}  
}  
}]  
}  
}  
},  
"size": 20,  
"from": 0  
}'

But it returns for example user like that :

{  
"\_index": "users",  
"\_type": "user",  
"\_id": "21578",  
"\_score": 1.0,  
"\_source": {  
"\_id": 21578,  
"email": "xxx@gmail.com",  
"affiliate\_program\_id": 1,  
"affiliate\_state\_id": 1,  
"status": "no\_verify",  
"apps\_events": [{  
"id": 159026,  
"source": "bien\_similaire",  
"frequency": "real\_time",  
"status": "active",  
"type": "rent",  
"user\_id": 21578,  
"affiliate\_program\_id": 1,  
"locations": [{  
"location\_id": 7521,  
"inf": 17198,  
"sup": 17213  
}, {  
"location\_id": 49364,  
"inf": 98942,  
"sup": 98943  
}],  
"property\_classes": ["appartment", "house", "appartment",  
"various"],  
"price\_min": "0",  
"price\_max": "1000"  
}, {  
"id": 99662,  
"source": "bien\_similaire",  
"frequency": "real\_time",  
"status": "inactive",  
"type": "rent",  
"user\_id": 21578,  
"affiliate\_program\_id": 1,  
"locations": [{  
"location\_id": 7540,  
"inf": 17138,  
"sup": 17145  
}, {  
"location\_id": 7647,  
"inf": 17136,  
"sup": 17137  
}],  
"property\_classes": ["appartment", "house", "appartment",  
"various"]  
}]  
}  
}

So it search with inf AND sup but not on one location object. It seems ES  
do : "inf greater than "any inf in apps.events.locations.¨" AND "sup less  
than any sup"....  
In my example, 98942 (inf) \> 59850 AND 17213 (sup from same apps\_events but  
not same locations) \< 59851 =\> wrong result.

Is that normal ? I don't like this behavious, I would like to compare  
location per location...

Any ideas?  
Thanks

--  
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:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [March 19, 2013, 10:04pm UTC](https://discuss.elastic.co/t/problem-with-multiple-range-in-nested/11210/2 "2013-03-19T22:04:32Z")

</div>

To achieve this locations have to be nested objects as well (the same way  
as events)

On Tuesday, March 19, 2013 1:30:41 PM UTC-4, Fabien Guiraud wrote:

> Hi,
> 
> I do that request :
> 
> curl -X GET '  
> [http://78.109.90.3:9200/users/user/\_search?from=0&load=&size=20&pretty](http://78.109.90.3:9200/users/user/_search?from=0&load=&size=20&pretty)'  
> -d '{  
> "query": {  
> "filtered": {  
> "query": {  
> "match\_all": {}  
> },  
> "filter": {  
> "and": [{  
> "nested": {  
> "path": "apps\_events",  
> "query": {  
> "filtered": {  
> "query": {  
> "match\_all": {}  
> },  
> "filter": {  
> "and": [{  
> "term": {  
> "apps\_events.status": "active"  
> }  
> }, {  
> "or": [{  
> "and": [{  
> "range": {
> 
> "apps\_events.locations.inf": {  
> "gte": 59850  
> }  
> }  
> }, {  
> "range": {
> 
> "apps\_events.locations.sup": {  
> "lte": 59851  
> }  
> }  
> }]  
> }]  
> }]  
> }  
> }  
> }  
> }  
> }]  
> }  
> }  
> },  
> "size": 20,  
> "from": 0  
> }'
> 
> But it returns for example user like that :
> 
> {  
> "\_index": "users",  
> "\_type": "user",  
> "\_id": "21578",  
> "\_score": 1.0,  
> "\_source": {  
> "\_id": 21578,  
> "email": "[x...@gmail.com](mailto:x...@gmail.com) \<javascript:\>",  
> "affiliate\_program\_id": 1,  
> "affiliate\_state\_id": 1,  
> "status": "no\_verify",  
> "apps\_events": [{  
> "id": 159026,  
> "source": "bien\_similaire",  
> "frequency": "real\_time",  
> "status": "active",  
> "type": "rent",  
> "user\_id": 21578,  
> "affiliate\_program\_id": 1,  
> "locations": [{  
> "location\_id": 7521,  
> "inf": 17198,  
> "sup": 17213  
> }, {  
> "location\_id": 49364,  
> "inf": 98942,  
> "sup": 98943  
> }],  
> "property\_classes": ["appartment", "house", "appartment",  
> "various"],  
> "price\_min": "0",  
> "price\_max": "1000"  
> }, {  
> "id": 99662,  
> "source": "bien\_similaire",  
> "frequency": "real\_time",  
> "status": "inactive",  
> "type": "rent",  
> "user\_id": 21578,  
> "affiliate\_program\_id": 1,  
> "locations": [{  
> "location\_id": 7540,  
> "inf": 17138,  
> "sup": 17145  
> }, {  
> "location\_id": 7647,  
> "inf": 17136,  
> "sup": 17137  
> }],  
> "property\_classes": ["appartment", "house", "appartment",  
> "various"]  
> }]  
> }  
> }
> 
> So it search with inf AND sup but not on one location object. It seems ES  
> do : "inf greater than "any inf in apps.events.locations.¨" AND "sup less  
> than any sup"....  
> In my example, 98942 (inf) \> 59850 AND 17213 (sup from same apps\_events  
> but not same locations) \< 59851 =\> wrong result.
> 
> Is that normal ? I don't like this behavious, I would like to compare  
> location per location...
> 
> Any ideas?  
> Thanks

--  
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:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [March 20, 2013, 10:28am UTC](https://discuss.elastic.co/t/problem-with-multiple-range-in-nested/11210/3 "2013-03-20T10:28:18Z")

</div>

Here is an example: [https://groups.google.com/forum/?fromgroups=#!topic/elasticsearch/jxTuRGvsDqk · GitHub](https://gist.github.com/imotov/5203687)

On Tuesday, March 19, 2013 6:04:32 PM UTC-4, Igor Motov wrote:

> To achieve this locations have to be nested objects as well (the same way  
> as events)
> 
> On Tuesday, March 19, 2013 1:30:41 PM UTC-4, Fabien Guiraud wrote:
> 
> > Hi,
> > 
> > I do that request :
> > 
> > curl -X GET '  
> > [http://78.109.90.3:9200/users/user/\_search?from=0&load=&size=20&pretty](http://78.109.90.3:9200/users/user/_search?from=0&load=&size=20&pretty)'  
> > -d '{  
> > "query": {  
> > "filtered": {  
> > "query": {  
> > "match\_all": {}  
> > },  
> > "filter": {  
> > "and": [{  
> > "nested": {  
> > "path": "apps\_events",  
> > "query": {  
> > "filtered": {  
> > "query": {  
> > "match\_all": {}  
> > },  
> > "filter": {  
> > "and": [{  
> > "term": {  
> > "apps\_events.status": "active"  
> > }  
> > }, {  
> > "or": [{  
> > "and": [{  
> > "range": {
> > 
> > "apps\_events.locations.inf": {  
> > "gte": 59850  
> > }  
> > }  
> > }, {  
> > "range": {
> > 
> > "apps\_events.locations.sup": {  
> > "lte": 59851  
> > }  
> > }  
> > }]  
> > }]  
> > }]  
> > }  
> > }  
> > }  
> > }  
> > }]  
> > }  
> > }  
> > },  
> > "size": 20,  
> > "from": 0  
> > }'
> > 
> > But it returns for example user like that :
> > 
> > {  
> > "\_index": "users",  
> > "\_type": "user",  
> > "\_id": "21578",  
> > "\_score": 1.0,  
> > "\_source": {  
> > "\_id": 21578,  
> > "email": "[x...@gmail.com](mailto:x...@gmail.com)",  
> > "affiliate\_program\_id": 1,  
> > "affiliate\_state\_id": 1,  
> > "status": "no\_verify",  
> > "apps\_events": [{  
> > "id": 159026,  
> > "source": "bien\_similaire",  
> > "frequency": "real\_time",  
> > "status": "active",  
> > "type": "rent",  
> > "user\_id": 21578,  
> > "affiliate\_program\_id": 1,  
> > "locations": [{  
> > "location\_id": 7521,  
> > "inf": 17198,  
> > "sup": 17213  
> > }, {  
> > "location\_id": 49364,  
> > "inf": 98942,  
> > "sup": 98943  
> > }],  
> > "property\_classes": ["appartment", "house", "appartment",  
> > "various"],  
> > "price\_min": "0",  
> > "price\_max": "1000"  
> > }, {  
> > "id": 99662,  
> > "source": "bien\_similaire",  
> > "frequency": "real\_time",  
> > "status": "inactive",  
> > "type": "rent",  
> > "user\_id": 21578,  
> > "affiliate\_program\_id": 1,  
> > "locations": [{  
> > "location\_id": 7540,  
> > "inf": 17138,  
> > "sup": 17145  
> > }, {  
> > "location\_id": 7647,  
> > "inf": 17136,  
> > "sup": 17137  
> > }],  
> > "property\_classes": ["appartment", "house", "appartment",  
> > "various"]  
> > }]  
> > }  
> > }
> > 
> > So it search with inf AND sup but not on one location object. It seems ES  
> > do : "inf greater than "any inf in apps.events.locations.¨" AND "sup less  
> > than any sup"....  
> > In my example, 98942 (inf) \> 59850 AND 17213 (sup from same apps\_events  
> > but not same locations) \< 59851 =\> wrong result.
> > 
> > Is that normal ? I don't like this behavious, I would like to compare  
> > location per location...
> > 
> > Any ideas?  
> > Thanks

--  
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:** ![Fabien\_Guiraud](https://avatars.discourse-cdn.com/v4/letter/f/57b2e6/32.png) [@Fabien\_Guiraud](https://discuss.elastic.co/u/Fabien_Guiraud)\
**Post date:** [March 20, 2013, 10:49am UTC](https://discuss.elastic.co/t/problem-with-multiple-range-in-nested/11210/4 "2013-03-20T10:49:30Z")

</div>

Okay, You're my god 🙂

Thanks a lot lot lot ! If I can do anything for you, let me know.

On Wednesday, March 20, 2013 11:28:18 AM UTC+1, Igor Motov wrote:

> Here is an example: [https://groups.google.com/forum/?fromgroups=#!topic/elasticsearch/jxTuRGvsDqk · GitHub](https://gist.github.com/imotov/5203687)
> 
> On Tuesday, March 19, 2013 6:04:32 PM UTC-4, Igor Motov wrote:
> 
> > To achieve this locations have to be nested objects as well (the same way  
> > as events)
> > 
> > On Tuesday, March 19, 2013 1:30:41 PM UTC-4, Fabien Guiraud wrote:
> > 
> > > Hi,
> > > 
> > > I do that request :
> > > 
> > > curl -X GET '  
> > > [http://78.109.90.3:9200/users/user/\_search?from=0&load=&size=20&pretty](http://78.109.90.3:9200/users/user/_search?from=0&load=&size=20&pretty)'  
> > > -d '{  
> > > "query": {  
> > > "filtered": {  
> > > "query": {  
> > > "match\_all": {}  
> > > },  
> > > "filter": {  
> > > "and": [{  
> > > "nested": {  
> > > "path": "apps\_events",  
> > > "query": {  
> > > "filtered": {  
> > > "query": {  
> > > "match\_all": {}  
> > > },  
> > > "filter": {  
> > > "and": [{  
> > > "term": {  
> > > "apps\_events.status":  
> > > "active"  
> > > }  
> > > }, {  
> > > "or": [{  
> > > "and": [{  
> > > "range": {
> > > 
> > > "apps\_events.locations.inf": {  
> > > "gte": 59850  
> > > }  
> > > }  
> > > }, {  
> > > "range": {
> > > 
> > > "apps\_events.locations.sup": {  
> > > "lte": 59851  
> > > }  
> > > }  
> > > }]  
> > > }]  
> > > }]  
> > > }  
> > > }  
> > > }  
> > > }  
> > > }]  
> > > }  
> > > }  
> > > },  
> > > "size": 20,  
> > > "from": 0  
> > > }'
> > > 
> > > But it returns for example user like that :
> > > 
> > > {  
> > > "\_index": "users",  
> > > "\_type": "user",  
> > > "\_id": "21578",  
> > > "\_score": 1.0,  
> > > "\_source": {  
> > > "\_id": 21578,  
> > > "email": "[x...@gmail.com](mailto:x...@gmail.com)",  
> > > "affiliate\_program\_id": 1,  
> > > "affiliate\_state\_id": 1,  
> > > "status": "no\_verify",  
> > > "apps\_events": [{  
> > > "id": 159026,  
> > > "source": "bien\_similaire",  
> > > "frequency": "real\_time",  
> > > "status": "active",  
> > > "type": "rent",  
> > > "user\_id": 21578,  
> > > "affiliate\_program\_id": 1,  
> > > "locations": [{  
> > > "location\_id": 7521,  
> > > "inf": 17198,  
> > > "sup": 17213  
> > > }, {  
> > > "location\_id": 49364,  
> > > "inf": 98942,  
> > > "sup": 98943  
> > > }],  
> > > "property\_classes": ["appartment", "house", "appartment",  
> > > "various"],  
> > > "price\_min": "0",  
> > > "price\_max": "1000"  
> > > }, {  
> > > "id": 99662,  
> > > "source": "bien\_similaire",  
> > > "frequency": "real\_time",  
> > > "status": "inactive",  
> > > "type": "rent",  
> > > "user\_id": 21578,  
> > > "affiliate\_program\_id": 1,  
> > > "locations": [{  
> > > "location\_id": 7540,  
> > > "inf": 17138,  
> > > "sup": 17145  
> > > }, {  
> > > "location\_id": 7647,  
> > > "inf": 17136,  
> > > "sup": 17137  
> > > }],  
> > > "property\_classes": ["appartment", "house", "appartment",  
> > > "various"]  
> > > }]  
> > > }  
> > > }
> > > 
> > > So it search with inf AND sup but not on one location object. It seems  
> > > ES do : "inf greater than "any inf in apps.events.locations.¨" AND "sup  
> > > less than any sup"....  
> > > In my example, 98942 (inf) \> 59850 AND 17213 (sup from same apps\_events  
> > > but not same locations) \< 59851 =\> wrong result.
> > > 
> > > Is that normal ? I don't like this behavious, I would like to compare  
> > > location per location...
> > > 
> > > Any ideas?  
> > > Thanks

--  
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:** ![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:45am UTC](https://discuss.elastic.co/t/problem-with-multiple-range-in-nested/11210/5 "2017-07-06T02:45:38Z")

</div>


