Term query on multiple fields based on a wildcard notation

Hi all,

I'm trying to do an exact match on an unknown number of fields.
I know that we can do a fulltext search on a set of fields using a multi_match like:
{
"multi_match": {
"fields":"fieldprefix_* ",
"query": "foo"
}
}
Now I would like to do the equivalent with a term query:
{
"term": {
"fields":"fieldprefix_* ",
"query": "foo"
}
}
Obviously, this notation is not supported as well as
{
"term": {
"fieldprefix_*": "foo"
}
}
So what is the closest syntax to achieve this use case? (of course, I don't know the name of all the fields starting by "fieldprefix_"

Thanks

bump up this one.
Does it mean there is no equivalent for an exact match?

You could override the analyzer in the query to use the keyword analyzer. That way, you'll be using the multi_match query to search for exact terms:

{
  "query": {
    "multi_match": {
      "fields": "fieldprefix_*",
      "query": "foo",
      "analyzer": "keyword"
    }
  }
}

thank you that's a very good idea and it indeed works.

So one more questions, how would you do the equivalent with terms?
terms accepts a list of values and not a single value.

Would you just use a should clause to test each individual value?

Thx

Yeah, a bool query with a number of queries in a should clause is probably the best way.

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