# How to prefer match on a longer percentage of the doc over a longer match?

**URL:** <https://discuss.elastic.co/t/how-to-prefer-match-on-a-longer-percentage-of-the-doc-over-a-longer-match/203173>\
**Category:** Elasticsearch\
**Created:** [October 11, 2019, 7:35am UTC](https://discuss.elastic.co/t/how-to-prefer-match-on-a-longer-percentage-of-the-doc-over-a-longer-match/203173 "2019-10-11T07:35:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lea\_Shallev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lea_shallev/32/55759_2.png) [@Lea\_Shallev](https://discuss.elastic.co/u/Lea_Shallev)\
**Post date:** [October 11, 2019, 7:35am UTC](https://discuss.elastic.co/t/how-to-prefer-match-on-a-longer-percentage-of-the-doc-over-a-longer-match/203173/1 "2019-10-11T07:35:15Z")

</div>

Hi,

I’m using elastic to search terms that were detected in a sentence of free text against an inner DB that was indexed.

I have a problem when my query appears in the DB with some tokens repetition.  
For example: I search the term “computer” while the DB includes 2 different documents:

1. “computer, dell computer”
2. “computer”  
In this case the first doc (“computer, dell computer”) will be returned because it includes more matches, but the second doc (“computer”) is a more appropriate response.

To clarify, there are cases when the repetition appears also in the query so I can’t just remove duplicates.

I found [this](https://l.facebook.com/l.php?u=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F24905534%2Felasticsearch-find-only-perfect-match%3Ffbclid%3DIwAR2Z6M1MbfImHVV_4uRfBjvgn3infoE7QSsH1-J6QKE8JTux75zWFv4Yfak&h=AT17cHFpSfFrTwnIXXy2CeMqKQvSD_0NWGY-nZISvEPVOgtKD3i80PEs9eublleOlXj6FUWd7517zWEg8KqD6ZrpGCr0e-yAPT7FhufYlz-pJK_rKHS0BEbYBDQ9cPhsNh2ehK4es9406tGW0Bs)solution, but since I’m searching for a free text I want to combine analyzers and fuzziness too.

Is there an option to make sure that **the text in the relevant field is contained in my query** (taking into account fuzziness) or to change scoring so elastic prefer match on a longer percentage of the doc over a longer match?

Here is my query:  
\<  
GET technology/\_search/  
{  
"explain":"true",  
"query": {  
"match": {  
"term": {  
"query": "computer",  
"fuzziness":"AUTO",  
"max\_expansions": 2,  
"prefix\_length":1,  
"fuzzy\_transpositions":true  
}  
}  
}  
}

> 

Thanks!

---

<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 8, 2019, 7:35am UTC](https://discuss.elastic.co/t/how-to-prefer-match-on-a-longer-percentage-of-the-doc-over-a-longer-match/203173/2 "2019-11-08T07:35:25Z")

</div>

Closed on November 8, 2019, 7:35am UTC

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