# Range search not working for string field

**URL:** <https://discuss.elastic.co/t/range-search-not-working-for-string-field/4389>\
**Category:** Elasticsearch\
**Created:** [May 12, 2011, 1:08pm UTC](https://discuss.elastic.co/t/range-search-not-working-for-string-field/4389 "2011-05-12T13:08:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![senthil\_prabhu](https://avatars.discourse-cdn.com/v4/letter/s/9e8a1a/32.png) [@senthil\_prabhu](https://discuss.elastic.co/u/senthil_prabhu)\
**Post date:** [May 12, 2011, 1:08pm UTC](https://discuss.elastic.co/t/range-search-not-working-for-string-field/4389/1 "2011-05-12T13:08:48Z")

</div>

Hi All,

Field(myfield) contains values like

```
tiff-0001
tiff-0002
tiff-0003
tiff-0004
tiff-0005
tiff-0006

```

is't possible to perform range search on these values. my field is  
mapped as standard analyzer.

i tried below queries:

$ curl -XGET '[http://localhost:9200/db371/metadata/\_search](http://localhost:9200/db371/metadata/_search)' -d  
' { "query" : { "range" : { "myfield" : { "from" : "tiff-0002", "to" :  
"tiff-0004","include\_lower" : true,"include\_upper" : true,"boost" :  
1.0 } } }, "from" : 0, "size" : 20,"explain" : false,"fields" :  
["myfield"] }'

$ curl -XGET '[http://localhost:9200/db371/metadata/\_search](http://localhost:9200/db371/metadata/_search)' -d  
' { "query" : { "range" : { "myfield" : { "from" : ""tiff-0002"",  
"to" : ""tiff-0004"","include\_lower" : true,"include\_upper" :  
true,"boost" : 1.0 } } }, "from" : 0, "size" : 20,"explain" :  
false,"fields" : ["myfield"] }'

---

<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:** [May 12, 2011, 9:59pm UTC](https://discuss.elastic.co/t/range-search-not-working-for-string-field/4389/2 "2011-05-12T21:59:42Z")

</div>

Thats probably because your field is analyzed, and thus broken down into two terms. You would want to map it with index set to "not\_analyzed". Here is a sample that shows that the standard analyzer (which is the default) will break it down to two terms:

curl -XPUT localhost:9200/test  
curl -XPOST localhost:9200/test/\_analyze -d '{tiff-0002}'

On Thursday, May 12, 2011 at 4:08 PM, senthil prabhu wrote:

> Hi All,
> 
> Field(myfield) contains values like
> 
> tiff-0001  
> tiff-0002  
> tiff-0003  
> tiff-0004  
> tiff-0005  
> tiff-0006
> 
> is't possible to perform range search on these values. my field is  
> mapped as standard analyzer.
> 
> i tried below queries:
> 
> $ curl -XGET '[http://localhost:9200/db371/metadata/\_search](http://localhost:9200/db371/metadata/_search)' -d  
> ' { "query" : { "range" : { "myfield" : { "from" : "tiff-0002", "to" :  
> "tiff-0004","include\_lower" : true,"include\_upper" : true,"boost" :  
> 1.0 } } }, "from" : 0, "size" : 20,"explain" : false,"fields" :  
> ["myfield"] }'
> 
> $ curl -XGET '[http://localhost:9200/db371/metadata/\_search](http://localhost:9200/db371/metadata/_search)' -d  
> ' { "query" : { "range" : { "myfield" : { "from" : ""tiff-0002"",  
> "to" : ""tiff-0004"","include\_lower" : true,"include\_upper" :  
> true,"boost" : 1.0 } } }, "from" : 0, "size" : 20,"explain" :  
> false,"fields" : ["myfield"] }'

---

<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, 4:06am UTC](https://discuss.elastic.co/t/range-search-not-working-for-string-field/4389/3 "2017-07-06T04:06:20Z")

</div>

Closed on July 6, 2017, 4:06am UTC


