User keyword and zero_terms_query in the same query

Hi we would like to build a query like the following

...
...
 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

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