Prefix query with any number

So I'm attempting to generate a query that will retrieve anything that
starts with a number. How would one accomplish this with ElasticSearch? I
tried passing an array to the prefix query but that seems to have failed
miserably. How would one do this?

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

On Wed, 2013-03-13 at 11:41 -0700, Bobby Tables wrote:

So I'm attempting to generate a query that will retrieve anything that
starts with a number. How would one accomplish this with
ElasticSearch? I tried passing an array to the prefix query but that
seems to have failed miserably. How would one do this?

Before version 0.90 you will have to do something like this:

curl -XGET 'http://127.0.0.1:9200/_all/_search?pretty=1' -d '
{
"query": {
"filtered": {
"query": { "match": { "title": "whatever" }}
"filter": {
"bool" : {
"should" : [
{ "prefix" : { "my_field" : 0 }},
{ "prefix" : { "my_field" : 1 }},
{ "prefix" : { "my_field" : 2 }},
{ "prefix" : { "my_field" : 3 }},
{ "prefix" : { "my_field" : 4 }},
{ "prefix" : { "my_field" : 5 }},
{ "prefix" : { "my_field" : 6 }},
{ "prefix" : { "my_field" : 7 }},
{ "prefix" : { "my_field" : 8 }},
{ "prefix" : { "my_field" : 9 }}
]
}
}
}
}
}
'
From 0.90 onwards, you can use the regexp filter:

curl -XGET 'http://127.0.0.1:9200/_all/_search?pretty=1' -d '
{
"query" : {
"filtered" : {
"filter" : {
"regexp" : {
"my_field" : "[0-9].*"
}
},
"query" : {
"match" : {
"title" : "whatever"
}
}
}
}
}
'

Beware though - these are very heavy searches. They need to examine
every term in "my_field" to see if they match.

More efficient would be to store this information in your doc at index
time, eg {"starts_with_number": true}

clint

--
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.
For more options, visit https://groups.google.com/groups/opt_out.