# How to find out how a query is matched?

**URL:** <https://discuss.elastic.co/t/how-to-find-out-how-a-query-is-matched/163649>\
**Category:** Elasticsearch\
**Created:** [January 10, 2019, 3:01am UTC](https://discuss.elastic.co/t/how-to-find-out-how-a-query-is-matched/163649 "2019-01-10T03:01:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NewHere](https://avatars.discourse-cdn.com/v4/letter/n/5e9695/32.png) [@NewHere](https://discuss.elastic.co/u/NewHere)\
**Post date:** [January 10, 2019, 3:01am UTC](https://discuss.elastic.co/t/how-to-find-out-how-a-query-is-matched/163649/1 "2019-01-10T03:01:19Z")

</div>

Say I have a field "Message" and some indexed values "quick brown fox", "foxy brownie" in documents. Is there an API in Elasticsearch that I can use to ask question like _How have we matched "brown fox" in "Message" of all the documents?_ and the result returns are

1. document 1 "Message" : "quick brown fox", matched: ["match", "match\_phrase", "phonetic"]
2. document 2 "Message" : "foxy brownie", matched: ["phonetic", "token\_count", "fuzzy", "edge\_ngram"]

i.e. Given a querying value, I want to know all the matched types within all configured analysers/filters/query types in the mapping.

I think the dumbest way to achieve the same is to ask separate queries per each configured type, like _Does "brown fox" match any document phonetically?_ _Does "brown fox" match any document with the same number of tokens?_ Is there a handy API that does all this in a single query manner?

---

<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:** [January 10, 2019, 6:05am UTC](https://discuss.elastic.co/t/how-to-find-out-how-a-query-is-matched/163649/2 "2019-01-10T06:05:32Z")

</div>

Have a look at: [https://www.elastic.co/guide/en/elasticsearch/reference/6.5/search-request-named-queries-and-filters.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.5/search-request-named-queries-and-filters.html)

---

<div class="post-metadata">

**Author:** ![NewHere](https://avatars.discourse-cdn.com/v4/letter/n/5e9695/32.png) [@NewHere](https://discuss.elastic.co/u/NewHere)\
**Post date:** [January 10, 2019, 6:49am UTC](https://discuss.elastic.co/t/how-to-find-out-how-a-query-is-matched/163649/3 "2019-01-10T06:49:42Z")

</div>

I see. You are saying I can give names to my queries and issue my queries possibly in one big query. I see that is no better than the dumb way, just a matter of asking it separately or in batch. Thanks anyway.

---

<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:** [February 7, 2019, 6:49am UTC](https://discuss.elastic.co/t/how-to-find-out-how-a-query-is-matched/163649/4 "2019-02-07T06:49:46Z")

</div>

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