# Match each token just once against each clause

**URL:** https://discuss.elastic.co/t/match-each-token-just-once-against-each-clause/226261
**Category:** Elasticsearch
**Created:** [April 2, 2020, 5:38pm UTC](https://discuss.elastic.co/t/match-each-token-just-once-against-each-clause/226261 "2020-04-02T17:38:30Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sgomez](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@sgomez](https://discuss.elastic.co/u/sgomez)
#### Post date: [April 2, 2020, 5:38pm UTC](https://discuss.elastic.co/t/match-each-token-just-once-against-each-clause/226261/1 "2020-04-02T17:38:30Z")

</div>

Hi,

I have a query that contains 2 different clauses. One for term query and one for prefix query. I want to know if there's a way for each of the tokens of the match field in the document I'm searching, to match just once against each of the clauses.

For example if I have a document that has a match field containing: "mary smith" and I'm searching for the name "mary m smith" both the term query and the prefix query would match against "mary". I need to find a way to match each token of the name I sent with a different token of the name in the document. In the example there shouldn't be a match because "mary" and "smith" found" a match but "m" didn't because the only possible match being a prefix was "mary" but this token already had a match.

Thanks and regards,

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [April 3, 2020, 2:10pm UTC](https://discuss.elastic.co/t/match-each-token-just-once-against-each-clause/226261/2 "2020-04-03T14:10:12Z")

</div>

Maybe it helps to explain your use-case completely without any technology terminology (imagine no elasticsearch, no match query, no prefix query, just a search term and documents). From a use-case perspective, what do you want to achieve here?

---

<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: [May 1, 2020, 2:10pm UTC](https://discuss.elastic.co/t/match-each-token-just-once-against-each-clause/226261/3 "2020-05-01T14:10:16Z")

</div>

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