# Term query on multiple fields based on a wildcard notation

**URL:** https://discuss.elastic.co/t/term-query-on-multiple-fields-based-on-a-wildcard-notation/183620
**Category:** Elasticsearch
**Created:** [May 30, 2019, 10:04pm UTC](https://discuss.elastic.co/t/term-query-on-multiple-fields-based-on-a-wildcard-notation/183620 "2019-05-30T22:04:03Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![marb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marb/32/19403_2.png) [@marb](https://discuss.elastic.co/u/marb)
#### Post date: [May 30, 2019, 10:04pm UTC](https://discuss.elastic.co/t/term-query-on-multiple-fields-based-on-a-wildcard-notation/183620/1 "2019-05-30T22:04:03Z")

</div>

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

---

<div class="post-metadata">

### Author: ![marb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marb/32/19403_2.png) [@marb](https://discuss.elastic.co/u/marb)
#### Post date: [June 3, 2019, 11:28pm UTC](https://discuss.elastic.co/t/term-query-on-multiple-fields-based-on-a-wildcard-notation/183620/2 "2019-06-03T23:28:18Z")

</div>

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

---

<div class="post-metadata">

### Author: ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)
#### Post date: [June 5, 2019, 12:43pm UTC](https://discuss.elastic.co/t/term-query-on-multiple-fields-based-on-a-wildcard-notation/183620/3 "2019-06-05T12:43:54Z")

</div>

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:

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

```

---

<div class="post-metadata">

### Author: ![marb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marb/32/19403_2.png) [@marb](https://discuss.elastic.co/u/marb)
#### Post date: [June 12, 2019, 5:10am UTC](https://discuss.elastic.co/t/term-query-on-multiple-fields-based-on-a-wildcard-notation/183620/4 "2019-06-12T05:10:45Z")

</div>

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

---

<div class="post-metadata">

### Author: ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)
#### Post date: [June 12, 2019, 8:20am UTC](https://discuss.elastic.co/t/term-query-on-multiple-fields-based-on-a-wildcard-notation/183620/5 "2019-06-12T08:20:19Z")

</div>

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

---

<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 10, 2019, 8:20am UTC](https://discuss.elastic.co/t/term-query-on-multiple-fields-based-on-a-wildcard-notation/183620/6 "2019-07-10T08:20:24Z")

</div>

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