# Upside down range query - match a single value against records having ranges

**URL:** <https://discuss.elastic.co/t/upside-down-range-query-match-a-single-value-against-records-having-ranges/8657>\
**Category:** Elasticsearch\
**Created:** [August 7, 2012, 8:13am UTC](https://discuss.elastic.co/t/upside-down-range-query-match-a-single-value-against-records-having-ranges/8657 "2012-08-07T08:13:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sandeep\_Srinivasa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sandeep_srinivasa/32/50506_2.png) [@Sandeep\_Srinivasa](https://discuss.elastic.co/u/Sandeep_Srinivasa)\
**Post date:** [August 7, 2012, 8:13am UTC](https://discuss.elastic.co/t/upside-down-range-query-match-a-single-value-against-records-having-ranges/8657/1 "2012-08-07T08:13:04Z")

</div>

hi,  
I tried looking this up, but was not able to find any material. I am not  
sure if I am attempting the impossible.  
Consider the following document in ES:

{  
"weight" : {  
"greater" : 5000,  
"lesser-or-equal" : 10000  
},  
"value" : "ABCD"  
}

{  
"weight" : {  
"greater" : 1000,  
"lesser-or-equal" : 2000  
},  
"value" : "XYZ"  
}

What I want to do is search for weight = 7000 and match record "ABCD" but  
not "XYZ". Basically, it is the opposite of range query, which lets you  
specify a range in your query and matches single valued records. Here, I am  
attempting to specify ranges in a document and query using a single valued  
query.

I dont know if this can even be done - is there a workaround to this kind  
of a behavior ?

Thanks!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 7, 2012, 9:22am UTC](https://discuss.elastic.co/t/upside-down-range-query-match-a-single-value-against-records-having-ranges/8657/2 "2012-08-07T09:22:40Z")

</div>

What about a range with

{  
"range" : {  
"lesser-or-equal" : {  
"from" : 7000  
}  
}  
}

with :

{  
"range" : {  
"greater" : {  
"to" : 7000  
}  
}  
}

All in a bool query with must for both of them?

Does it make sense for your use case?

Le 7 août 2012 à 10:13, Sandeep Srinivasa [sandys@gmail.com](mailto:sandys@gmail.com) a écrit :

> hi,  
> I tried looking this up, but was not able to find any material. I am not sure  
> if I am attempting the impossible.  
> Consider the following document in ES:
> 
> {  
> "weight" : {  
> "greater" : 5000,  
> "lesser-or-equal" : 10000  
> },  
> "value" : "ABCD"  
> }
> 
> {  
> "weight" : {  
> "greater" : 1000,  
> "lesser-or-equal" : 2000  
> },  
> "value" : "XYZ"  
> }
> 
> What I want to do is search for weight = 7000 and match record "ABCD" but not  
> "XYZ". Basically, it is the opposite of range query, which lets you specify a  
> range in your query and matches single valued records. Here, I am attempting  
> to specify ranges in a document and query using a single valued query.
> 
> I dont know if this can even be done - is there a workaround to this kind of  
> a behavior ?
> 
> Thanks!

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

---

<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:17am UTC](https://discuss.elastic.co/t/upside-down-range-query-match-a-single-value-against-records-having-ranges/8657/3 "2017-07-06T03:17:30Z")

</div>

Closed on July 6, 2017, 3:17am UTC


