# Exclude fields from multi\_match

**URL:** <https://discuss.elastic.co/t/exclude-fields-from-multi-match/336034>\
**Category:** Elasticsearch\
**Created:** [June 15, 2023, 3:41am UTC](https://discuss.elastic.co/t/exclude-fields-from-multi-match/336034 "2023-06-15T03:41:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ctatshell](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@ctatshell](https://discuss.elastic.co/u/ctatshell)\
**Post date:** [June 15, 2023, 3:41am UTC](https://discuss.elastic.co/t/exclude-fields-from-multi-match/336034/1 "2023-06-15T03:41:57Z")

</div>

I have an index with an dynamic object property called "sourceData" which contains various properties. I am trying execute multi\_match using phrase type and one of the analyzers we have setup and the fields we must use "sourceData.\*" since we do not know all of the possibilities.

looking at the mapping that was created when the data was populated, all properties under "sourceData" contains type: "text" and "keyword"

snippet:  
"multi\_match":{  
"query": "some random phrase",  
"fields": ["sourceData.\*"],  
"type": "phrase",  
"analyzer": "custom\_english"  
}

When I run this, I get an error that Can only use phrase queries on text fields - not on [source.PROPERTYNAME.keyword] which is type [keyword]

Since I do not have all possible "sourceData" properties, I have to use the \* in the fields. So, is there a way to exclude all of the [keyword] for each of those properties?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [June 15, 2023, 2:39pm UTC](https://discuss.elastic.co/t/exclude-fields-from-multi-match/336034/2 "2023-06-15T14:39:02Z")

</div>

Hi @ctatshell

Could you provide the complete error log?  
The phrase type in multi\_match is a match\_phrase query.  
If you run match\_phrase query do you get the same error?

---

<div class="post-metadata">

**Author:** ![ctatshell](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@ctatshell](https://discuss.elastic.co/u/ctatshell)\
**Post date:** [June 16, 2023, 2:10am UTC](https://discuss.elastic.co/t/exclude-fields-from-multi-match/336034/3 "2023-06-16T02:10:56Z")

</div>

Thanks for your reply.

Do not really need to show the whole error log here. It is a query\_shard\_exception with the reason "failed to create query: Can only use phrase queries on text fields - not on [sourceData.PROPERTYNAME.keyword]. Since sourceData is a dynamic object, the mapping for each of those fields is text with additional field of keyword.

Since match\_phrase does not work on multiple fields and I need to use multiple fields it is not much help here.

The question really is, is there a way to exclude properties from the fields parameter of multi\_match.

If it is not possible, then I will have to write custom dynamic template with only text fields and not keyword fields and recreate my index. It is very large index so I don't really want to do this.

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [June 16, 2023, 4:52am UTC](https://discuss.elastic.co/t/exclude-fields-from-multi-match/336034/4 "2023-06-16T04:52:53Z")

</div>

Ok. Try to use Lenient. This will ignore errors.

```auto
{
        "multi_match": {
          "query": "some random phrase",
          "fields": [
            "sourceData.*"
          ],
          "type": "phrase",
          "lenient": true,
          "analyzer": "custom_english"
        }
      }

```

---

<div class="post-metadata">

**Author:** ![ctatshell](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@ctatshell](https://discuss.elastic.co/u/ctatshell)\
**Post date:** [June 16, 2023, 5:43am UTC](https://discuss.elastic.co/t/exclude-fields-from-multi-match/336034/5 "2023-06-16T05:43:19Z")

</div>

Yes, that did work and solved my problem.

Thank you.

---

<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:** [July 14, 2023, 5:43am UTC](https://discuss.elastic.co/t/exclude-fields-from-multi-match/336034/6 "2023-07-14T05:43:24Z")

</div>

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