"Contains" query in a numberic/date field

(wifly) #1

Hi all,
I'm trying to perform a contains query in a field which is numeric, is that possible?
Let's say for example

"index": { "mappings": { "element": { "properties": { "name": { "type": "string }, "code": { "type": "integer" }, "amendmentDate": { "type": "date", "format": "dd/MM/yyyy" } } } } }

I'm trying things like:
{ "query":{ "query_string":{ "query":"(code: /.*1313.*/)" } } }

my objective is to find numbers like 1313, 13135, 5551313555,

Is there a way to cast the field to string before applying the query, or search over a computed "stringized" field ?

It would be great to be able to do it over the date field too, that's my next step :slight_smile:

I'm getting NumberFormatExceptions for numbers, "Invalid format: "20" is too short" for dates... and have tried with regexes, without, with quotes ...

Sorry if it's very obvious or already answered, I come from the sql world.. I've been digging in the documentation and the forums for a few hours and haven't been able to find anything.
Thanks in advance.

(Dan Markhasin) #2

You can do it with a script:

"script":"doc['code'].value.toString() =~ /.1313./"

(system) #3

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