Elastic search query containing '!' in regexp query doesnt match against any results


(Nikita) #1

Elastic search below query doesn't return any results:

1.) {"query":{"regexp":{"field_name":".*f04((?!z).)*"}}

Why a query like above doesn't return any result?

I'm expecting results like this : ['f00bar', 'f04bar', 'f04barbuh', 'f04ba']

whereas below one returns:

2.) {"query":{"regexp":{"field_name":".*f04((?!z).)*.*"}}

Results returned by this : ['f04bar', 'f04barbuh', 'f04ba', 'f04baz']

I know that 2nd query returns result because of .* at the end, is there anything wrong with '!' in the regexp, it should be something else? how do we use ! as the part of regexp to specify ba should not be followed by z .

Mapping loos like below:

{ "field_name1": { "type": "keyword" }, "field_name2": { "type": "keyword" }, "query": { "properties": { "regexp": { "properties": { "field_name1": { "type": "keyword" }, "field_name2": { "type": "keyword" } } } } } }


Regexp character '!' doesnt work in ES dsl query even on type set as 'keyword' in mappings
(David Pilato) #2