Range search not working for string field


(senthil prabhu) #1

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' -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' -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"] }'


(Shay Banon) #2

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' -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' -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"] }'


(system) #3