# Right way to achieve some sort of "reverse minimum should match = 100%"

**URL:** <https://discuss.elastic.co/t/right-way-to-achieve-some-sort-of-reverse-minimum-should-match-100/202290>\
**Category:** Elasticsearch\
**Created:** [October 4, 2019, 6:50am UTC](https://discuss.elastic.co/t/right-way-to-achieve-some-sort-of-reverse-minimum-should-match-100/202290 "2019-10-04T06:50:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![babayotakun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/babayotakun/32/64403_2.png) [@babayotakun](https://discuss.elastic.co/u/babayotakun)\
**Post date:** [October 4, 2019, 6:50am UTC](https://discuss.elastic.co/t/right-way-to-achieve-some-sort-of-reverse-minimum-should-match-100/202290/1 "2019-10-04T06:50:36Z")

</div>

Hi  
In our project we often dealing with logic like "full document field should be present in the lookup query".  
We've developed number of solutions for this (usage of highlighter, generation of tons of queries with all lookup term combinations, etc). But all this approaches are too slow.  
Maybe there is a faster and simpler way to implement these logic?  
For example you have document  
`{"text": "hello world"}`  
It should be found by query  
`hello world my friend`  
But not found by query  
`hello my friend`

---

<div class="post-metadata">

**Author:** ![loren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loren/32/44942_2.png) [@loren](https://discuss.elastic.co/u/loren)\
**Post date:** [October 4, 2019, 12:53pm UTC](https://discuss.elastic.co/t/right-way-to-achieve-some-sort-of-reverse-minimum-should-match-100/202290/2 "2019-10-04T12:53:23Z")

</div>

Seems like you could use a [terms set query](https://www.elastic.co/guide/en/elasticsearch/reference/master/query-dsl-terms-set-query.html) here, where `required_matches` is the number of tokens in each doc's `text` field.

---

<div class="post-metadata">

**Author:** ![babayotakun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/babayotakun/32/64403_2.png) [@babayotakun](https://discuss.elastic.co/u/babayotakun)\
**Post date:** [October 7, 2019, 10:05am UTC](https://discuss.elastic.co/t/right-way-to-achieve-some-sort-of-reverse-minimum-should-match-100/202290/3 "2019-10-07T10:05:26Z")

</div>

Thank you!

---

<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:** [November 4, 2019, 10:18am UTC](https://discuss.elastic.co/t/right-way-to-achieve-some-sort-of-reverse-minimum-should-match-100/202290/4 "2019-11-04T10:18:27Z")

</div>

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