Exclude fields from multi_match

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"

"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?

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?

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.

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

        "multi_match": {
          "query": "some random phrase",
          "fields": [
          "type": "phrase",
          "lenient": true,
          "analyzer": "custom_english"

Yes, that did work and solved my problem.

Thank you.

1 Like

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