Query on numeric data type

Is it possible to do a wildcard search in a long or a numeric field in elasticsearch ?

1 Like

Hey,

wildcard query works on terms only. Can you explain your use-case? Wouldnt ranges work better, or if not, maybe another index time data structure?

--Alex

The problem is, if the long field has value 120450, 120445, 120656. Please find the query below.

{"from":0,"size":10,"query":{"nested":{"query":{"bool":{"must":[{"query_string":{"query":"120","fields":["alist.articleId"]}}]}},"path":"alist"}}}

The response should return all the three documents which has partial match for 120. Is it possible to achieve this in long or a numeric field ?

Hey,

you could index the number as a string field as well and then use the wildcard query (which you did not use in your example, slightly confused).

--Alex

Alex, I should not change the mapping of the index. Can you please let me know is it possible to achieve using numeric fields ?

Hey,

no it is not. You could index a field as string and number if you need - I do not see why this is a problem. Check out the Elasticsearch documentation about the fields parameter in mappings.

--Alex

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.