Searching Integer with wild cards

(Prashant) #1

Can anyone please help me identifying how to use wild cards for integer searches? I tried using the inline script but no luck. This is what I have tried (I have also tried with different regex pattern which works for javascript but here with the query, it does not work)..

"query": {
        "bool": {
            "must": {
            	"script" : {
            		"script" : {
            			"inline" : "doc['statCode'].value.toString().match('/9.*/')",
            			"lang" : "javascript"

(David Pilato) #2

Why do you want to do something so complex and so bad in term of performance?

What are the different values you can have for statCode? Can't you use a range query instead?

(Prashant) #3

My requirement is to support wild card search for integer fields? Do you suggest any other way to achieve? how can we use range query for this? If the field has the value say 00123789 and if I want to search with *7 how do I use range query for it?

(David Pilato) #4

Some comments:

(Prashant) #5

Yes I have indexed those as String and those are working as well but sorting is an issue currently. if I index them as string then it will not sort it as number (sorting order will not be proper). so I am trying to see if we have wildcard support for integer fields or there is an easy way to achieve it.

(David Pilato) #6

You can index the same field as both text and number. Then sort on the later.

(system) #7

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