# User keyword and zero\_terms\_query in the same query

**URL:** <https://discuss.elastic.co/t/user-keyword-and-zero-terms-query-in-the-same-query/290177>\
**Category:** Elasticsearch\
**Created:** [November 25, 2021, 1:06pm UTC](https://discuss.elastic.co/t/user-keyword-and-zero-terms-query-in-the-same-query/290177 "2021-11-25T13:06:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabry](https://avatars.discourse-cdn.com/v4/letter/f/c77e96/32.png) [@fabry](https://discuss.elastic.co/u/fabry)\
**Post date:** [November 25, 2021, 1:06pm UTC](https://discuss.elastic.co/t/user-keyword-and-zero-terms-query-in-the-same-query/290177/1 "2021-11-25T13:06:52Z")

</div>

Hi we would like to build a query like the following

```auto
...
...
 bool: {
   must: [
     match : {
        myfield.myfield2 : {
           query: "myvalue",
           zero_terms_query: "all"
        }
     }
   ]
 }
...
...

```

And it is working like expected. If "myvalue" is not empty we get the result, otherwise the field `myfield.myfield2` is "kind of" ignored in the whole query.

The issue is when we add the suffix .keyword: `myfield.myfield2.keyword`  
in this situation if "myvalue" is an empty string we do not get any result.

Basically we would like to ignore the query on the field `myfield.myfield2.keyword` if the provided value is empty, otherwise we would like to get the exact match without tokenization.

Is it possible? how?  
Thanks

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 23, 2021, 1:07pm UTC](https://discuss.elastic.co/t/user-keyword-and-zero-terms-query-in-the-same-query/290177/2 "2021-12-23T13:07:38Z")

</div>

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