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

**URL:** <https://discuss.elastic.co/t/elastic-search-query-containing-in-regexp-query-doesnt-match-against-any-results/143799>\
**Category:** Elasticsearch\
**Created:** [August 10, 2018, 5:24am UTC](https://discuss.elastic.co/t/elastic-search-query-containing-in-regexp-query-doesnt-match-against-any-results/143799 "2018-08-10T05:24:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikitag](https://avatars.discourse-cdn.com/v4/letter/n/ce7236/32.png) [@nikitag](https://discuss.elastic.co/u/nikitag)\
**Post date:** [August 10, 2018, 5:24am UTC](https://discuss.elastic.co/t/elastic-search-query-containing-in-regexp-query-doesnt-match-against-any-results/143799/1 "2018-08-10T05:24:17Z")

</div>

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" } } } } } }`

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 10, 2018, 8:24pm UTC](https://discuss.elastic.co/t/elastic-search-query-containing-in-regexp-query-doesnt-match-against-any-results/143799/2 "2018-08-10T20:24:39Z")

</div>


