# Scoring longest continuous string in documents

**URL:** <https://discuss.elastic.co/t/scoring-longest-continuous-string-in-documents/509>\
**Category:** Elasticsearch\
**Created:** [May 11, 2015, 3:10pm UTC](https://discuss.elastic.co/t/scoring-longest-continuous-string-in-documents/509 "2015-05-11T15:10:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexis\_Berger](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@Alexis\_Berger](https://discuss.elastic.co/u/Alexis_Berger)\
**Post date:** [May 11, 2015, 3:10pm UTC](https://discuss.elastic.co/t/scoring-longest-continuous-string-in-documents/509/1 "2015-05-11T15:10:11Z")

</div>

Hi,

I have a dataset containing about 15M documents.  
Each document has one field which contains a small text 50 words at max.

I made lots of search query tests until I found the query I needed, managing stop words and missing words.  
It is a function score query wrapping a common terms query, and filtering the results with a phrase match query:  
(for the given example, let say that the cutoff\_frequency value is right and skip stop words correctly)

GET xxxx/\_search  
{  
"fields": ["myField"],  
"from" : 0,  
"size" : 10,  
"query" : {  
"function\_score" : {  
"query" : {  
"bool" : {  
"must" : {  
"common": {  
"myField": {  
"query": "word1 word2 word3 word4",  
"cutoff\_frequency": 0.149,  
"low\_freq\_operator": "or",  
"high\_freq\_operator": "or",  
"minimum\_should\_match": 3  
}  
}  
}  
}  
},  
"functions" : [ {  
"filter" : {  
"query" : {  
"match" : {  
"oneField.normal" : {  
"query" : "word1 word2 word3 word4",  
"type" : "phrase",  
"slop" : 0  
}  
}  
}  
},  
"weight" : 1.0  
},  
"score\_mode" : "sum",  
"boost\_mode" : "sum"  
}  
}  
}

Everything is good, except documents ranking.  
The default similarity does not seem to match my needs. I need the best scores for documents that have the longest continous string (most adjacent words).  
What is the best way to achieve this ranking? Using another similarity? Maybe I missed a special query in the documentation...

Any help/advice would be much appreciated!  
Thanks

BTW I am using ES 1.5 🙂

---

<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 6, 2017, 12:14am UTC](https://discuss.elastic.co/t/scoring-longest-continuous-string-in-documents/509/2 "2017-07-06T00:14:37Z")

</div>


