Query to match digit sequence of numeric field?

Hi,

New to ES so forgive if answer's obvious. I have a domain object 'widget'
with numeric field 'code'. Can I construct a DSL query to return all
widgets whose 'code' value contains a given sequence of digits (think
autocomplete use case)? For example input '13' would match widgets with
codes: 13, 1013, 40131.

I tried using a wildcard query
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html(with
val = "13*") but looks like that type of query does not work on numeric
fields. Also tried regexp filterhttp://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-regexp-filter.htmlwithout success.

Do I need to map 'code' as a string field and then use regexp filter? is
the answer different if the field is instead '_id'http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-id-field.html
?

thank you,
-nikita

--
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.

You could use a String type with a ngram analyzer. Wildcard and prefix queries are slower and I would not recommend them especially for an autocomplete feature which has to be fast!
Also, you could look at the suggest API. Unsure if it will answer to your use case though.

You can analyze _id field but I would prefer using another field than _id which is more a technical field to me than a business field.

HTH

David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 30 oct. 2013 à 00:42, Nikita Tovstoles nikita.tovstoles@gmail.com a écrit :

Hi,

New to ES so forgive if answer's obvious. I have a domain object 'widget' with numeric field 'code'. Can I construct a DSL query to return all widgets whose 'code' value contains a given sequence of digits (think autocomplete use case)? For example input '13' would match widgets with codes: 13, 1013, 40131.

I tried using a wildcard query (with val = "13*") but looks like that type of query does not work on numeric fields. Also tried regexp filter without success.

Do I need to map 'code' as a string field and then use regexp filter? is the answer different if the field is instead '_id'?

thank you,
-nikita

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.

--
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.