# Question about range query

**URL:** <https://discuss.elastic.co/t/question-about-range-query/6102>\
**Category:** Elasticsearch\
**Created:** [December 8, 2011, 7:28pm UTC](https://discuss.elastic.co/t/question-about-range-query/6102 "2011-12-08T19:28:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![caphrim007](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/caphrim007/32/2379_2.png) [@caphrim007](https://discuss.elastic.co/u/caphrim007)\
**Post date:** [December 8, 2011, 7:28pm UTC](https://discuss.elastic.co/t/question-about-range-query/6102/1 "2011-12-08T19:28:40Z")

</div>

Hi,

I'm using ES 0.17.7 and making GET requests via the "\_search?q=" URI  
just for testing purposes before I turn the query into a JSON string.

I'm trying to do a range query. Here it is

```
/_search?q=sourceSize:[990+TO+991]

```

And it is returning documents with the following sourceSize fields and  
vals.

```
"sourceSize": "9906",
"sourceSize": "9909112",
"sourceSize": "990"

```

I interpret the range query to be values literally from 990 to 991,  
which should then only return the "990" document above. But it appears  
that ES is interpreting the query to be something like [990\*+TO+991\*].

Can I use the \_search endpoint to have it do a literal value search  
instead of what appears to be a wildcard search?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [December 8, 2011, 8:37pm UTC](https://discuss.elastic.co/t/question-about-range-query/6102/2 "2011-12-08T20:37:46Z")

</div>

Why not use a range query?

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

The normal scenario is to have a POST query with an json query in it.

Also do you have multiple identical properties per document or a  
mapping configuration?

Peter.

On 8 Dez., 20:28, caphrim007 [caphrim...@gmail.com](mailto:caphrim...@gmail.com) wrote:

> Hi,
> 
> I'm using ES 0.17.7 and making GET requests via the "\_search?q=" URI  
> just for testing purposes before I turn the query into a JSON string.
> 
> I'm trying to do a range query. Here it is
> 
> ```
> /_search?q=sourceSize:[990+TO+991]
> 
> ```
> 
> And it is returning documents with the following sourceSize fields and  
> vals.
> 
> ```
> "sourceSize": "9906",
> "sourceSize": "9909112",
> "sourceSize": "990"
> 
> ```
> 
> I interpret the range query to be values literally from 990 to 991,  
> which should then only return the "990" document above. But it appears  
> that ES is interpreting the query to be something like [990\*+TO+991\*].
> 
> Can I use the \_search endpoint to have it do a literal value search  
> instead of what appears to be a wildcard search?
> 
> Thanks in advance

---

<div class="post-metadata">

**Author:** ![caphrim007](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/caphrim007/32/2379_2.png) [@caphrim007](https://discuss.elastic.co/u/caphrim007)\
**Post date:** [December 9, 2011, 4:17am UTC](https://discuss.elastic.co/t/question-about-range-query/6102/3 "2011-12-09T04:17:51Z")

</div>

I _am_ using a range query. I already answered why I'm not using JSON  
in the question I asked. In case you missed it.

"""  
...and making GET requests via the "\_search?q=" URI  
just for testing purposes before I turn the query into a JSON string.  
"""

My documents have fields. Not sure what you mean by identical, because  
a document cannot have more than one field with the same name, but if  
you mean do I have documents that have identical field names, then  
yes, some documents have the same field names as other documents. My  
example illustrates that; the "sourceSize" field.

The mapping configuration is the default supplied with ES.

-Tim

On Dec 8, 2:37 pm, Karussell [tableyourt...@googlemail.com](mailto:tableyourt...@googlemail.com) wrote:

> Why not use a range query?
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/range-query.html)
> 
> The normal scenario is to have a POST query with an json query in it.
> 
> Also do you have multiple identical properties per document or a  
> mapping configuration?
> 
> Peter.
> 
> On 8 Dez., 20:28, caphrim007 [caphrim...@gmail.com](mailto:caphrim...@gmail.com) wrote:
> 
> > Hi,
> 
> > I'm using ES 0.17.7 and making GET requests via the "\_search?q=" URI  
> > just for testing purposes before I turn the query into a JSON string.
> 
> > I'm trying to do a range query. Here it is
> 
> > ```
> > /_search?q=sourceSize:[990+TO+991]
> > 
> > ```
> 
> > And it is returning documents with the following sourceSize fields and  
> > vals.
> 
> > ```
> > "sourceSize": "9906",
> > "sourceSize": "9909112",
> > "sourceSize": "990"
> > 
> > ```
> 
> > I interpret the range query to be values literally from 990 to 991,  
> > which should then only return the "990" document above. But it appears  
> > that ES is interpreting the query to be something like [990\*+TO+991\*].
> 
> > Can I use the \_search endpoint to have it do a literal value search  
> > instead of what appears to be a wildcard search?
> 
> > Thanks in advance

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [December 9, 2011, 10:54am UTC](https://discuss.elastic.co/t/question-about-range-query/6102/4 "2011-12-09T10:54:04Z")

</div>

The questions were only asked because this is the normal way of  
helping to track it down ...

give us the docs you are indexing and the query (aka curl recreation)  
as it should work. I fear your are indexing the values as strings:

"sourceSize": "9906"

and not as number

"sourceSize": 9906

Peter.

---

<div class="post-metadata">

**Author:** ![caphrim007](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/caphrim007/32/2379_2.png) [@caphrim007](https://discuss.elastic.co/u/caphrim007)\
**Post date:** [December 9, 2011, 9:22pm UTC](https://discuss.elastic.co/t/question-about-range-query/6102/5 "2011-12-09T21:22:40Z")

</div>

yep, I'm sure I'm indexing them as strings; the \_mapping endpoint confirms  
that.

How do range queries work with strings? Is the answer "the behavior is  
undefined"?

Is ES looking for anything that begins with the "from" value, in this case  
anything that begins with 990 ? and also looking for anything that begins  
with 901 ?

My documents are kinda big, see attachment for 1 of them. The rest of the  
couple hundred thousand are permutations of that. If you want to test it on  
small scale, just create a couple docs with 1 field, a numeric that is  
stored as a string, and try to do a range query on it (using my example).

```
"sourceSize": "9906",
"sourceSize": "9909112",
"sourceSize": "990"

```

Is what you would get. But I don't "get" how the 1st or 2nd entries qualify  
as a match, because even as strings they are longer than my range. So I  
don't understand why they match. I might understand if ES returned

```
"sourceSize": "992"
"sourceSize": "993"
"sourceSize": "994"

```

Because in that case, the strings are at least the same length as the  
values in the range query (900 and 901) even if the returned matches are  
"incorrect" from a numeric point of view.

How do range queries for string values work in ES?

-Tim

---

<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:** [December 9, 2011, 10:41pm UTC](https://discuss.elastic.co/t/question-about-range-query/6102/6 "2011-12-09T22:41:56Z")

</div>

strings based range query is lexicography. If you want numeric ones, you  
can map them as numbers (or index them as numbers).

On Fri, Dec 9, 2011 at 11:22 PM, caphrim007 [caphrim007@gmail.com](mailto:caphrim007@gmail.com) wrote:

> yep, I'm sure I'm indexing them as strings; the \_mapping endpoint confirms  
> that.
> 
> How do range queries work with strings? Is the answer "the behavior is  
> undefined"?
> 
> Is ES looking for anything that begins with the "from" value, in this case  
> anything that begins with 990 ? and also looking for anything that begins  
> with 901 ?
> 
> My documents are kinda big, see attachment for 1 of them. The rest of the  
> couple hundred thousand are permutations of that. If you want to test it on  
> small scale, just create a couple docs with 1 field, a numeric that is  
> stored as a string, and try to do a range query on it (using my example).
> 
> ```
> "sourceSize": "9906",
> "sourceSize": "9909112",
> "sourceSize": "990"
> 
> ```
> 
> Is what you would get. But I don't "get" how the 1st or 2nd entries  
> qualify as a match, because even as strings they are longer than my range.  
> So I don't understand why they match. I might understand if ES returned
> 
> ```
> "sourceSize": "992"
> "sourceSize": "993"
> "sourceSize": "994"
> 
> ```
> 
> Because in that case, the strings are at least the same length as the  
> values in the range query (900 and 901) even if the returned matches are  
> "incorrect" from a numeric point of view.
> 
> How do range queries for string values work in ES?
> 
> -Tim

---

<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:45am UTC](https://discuss.elastic.co/t/question-about-range-query/6102/7 "2017-07-06T03:45:50Z")

</div>


