# Is it possible to wildcard search AND highlight or name the matching query in the results?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-wildcard-search-and-highlight-or-name-the-matching-query-in-the-results/188367>\
**Category:** Elasticsearch\
**Created:** [July 1, 2019, 3:55pm UTC](https://discuss.elastic.co/t/is-it-possible-to-wildcard-search-and-highlight-or-name-the-matching-query-in-the-results/188367 "2019-07-01T15:55:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JMcKitrick](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jmckitrick/32/49184_2.png) [@JMcKitrick](https://discuss.elastic.co/u/JMcKitrick)\
**Post date:** [July 1, 2019, 3:55pm UTC](https://discuss.elastic.co/t/is-it-possible-to-wildcard-search-and-highlight-or-name-the-matching-query-in-the-results/188367/1 "2019-07-01T15:55:51Z")

</div>

We have about a dozen fields we want to search with wildcards, but we need to know which fields have matched. I've used named queries and highlighting, but I don't believe those work with wildcard searches.

So, when searching for 'john' we want to match first name 'Johnny', last name 'Johnson', and email address 'john123@example.com' and show which of those fields match in each of the hits.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 1, 2019, 4:15pm UTC](https://discuss.elastic.co/t/is-it-possible-to-wildcard-search-and-highlight-or-name-the-matching-query-in-the-results/188367/2 "2019-07-01T16:15:07Z")

</div>

I wonder if `explain: true` could help you?  
Otherwise indeed named queries that you define within a `bool` query inside a `should` array would probably be better.

---

<div class="post-metadata">

**Author:** ![JMcKitrick](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jmckitrick/32/49184_2.png) [@JMcKitrick](https://discuss.elastic.co/u/JMcKitrick)\
**Post date:** [July 1, 2019, 5:19pm UTC](https://discuss.elastic.co/t/is-it-possible-to-wildcard-search-and-highlight-or-name-the-matching-query-in-the-results/188367/3 "2019-07-01T17:19:42Z")

</div>

Actually, I just discovered I can add the 'highlight' option to 'query\_string' queries. The docs didn't indicate that, but it seems to work. That allow me to use wildcards and shows what fields matched.

---

<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 29, 2019, 5:20pm UTC](https://discuss.elastic.co/t/is-it-possible-to-wildcard-search-and-highlight-or-name-the-matching-query-in-the-results/188367/4 "2019-07-29T17:20:02Z")

</div>

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