# Limiting the relevancy score of all the searched documents

**URL:** <https://discuss.elastic.co/t/limiting-the-relevancy-score-of-all-the-searched-documents/48123>\
**Category:** Elasticsearch\
**Created:** [April 22, 2016, 6:53am UTC](https://discuss.elastic.co/t/limiting-the-relevancy-score-of-all-the-searched-documents/48123 "2016-04-22T06:53:57Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![divyanshu\_marwah](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@divyanshu\_marwah](https://discuss.elastic.co/u/divyanshu_marwah)\
**Post date:** [April 22, 2016, 6:53am UTC](https://discuss.elastic.co/t/limiting-the-relevancy-score-of-all-the-searched-documents/48123/1 "2016-04-22T06:53:57Z")

</div>

I want to limit the score of all the searched documents within 0 and 1.Please suggest a way to do this.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 24, 2016, 12:23am UTC](https://discuss.elastic.co/t/limiting-the-relevancy-score-of-all-the-searched-documents/48123/2 "2016-04-24T00:23:19Z")

</div>

Why would you want to do this?  
And do you want to filter everything out that has a score \<0 and \>1?

---

<div class="post-metadata">

**Author:** ![divyanshu\_marwah](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@divyanshu\_marwah](https://discuss.elastic.co/u/divyanshu_marwah)\
**Post date:** [April 25, 2016, 6:02am UTC](https://discuss.elastic.co/t/limiting-the-relevancy-score-of-all-the-searched-documents/48123/3 "2016-04-25T06:02:53Z")

</div>

No, Actually I want that all the scores should come in between 0-1.I don't want to filter the results according to score, rather I want to limit all the scores \<0 and \>1. Normally there is no limit of the scores that are calculated, so in order to get some uniform results, I want all the matching results of the query , but all the scores should be limited within 0 to 1.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 25, 2016, 6:11am UTC](https://discuss.elastic.co/t/limiting-the-relevancy-score-of-all-the-searched-documents/48123/4 "2016-04-25T06:11:24Z")

</div>

You cannot do this.

---

<div class="post-metadata">

**Author:** ![divyanshu\_marwah](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@divyanshu\_marwah](https://discuss.elastic.co/u/divyanshu_marwah)\
**Post date:** [April 25, 2016, 6:15am UTC](https://discuss.elastic.co/t/limiting-the-relevancy-score-of-all-the-searched-documents/48123/5 "2016-04-25T06:15:44Z")

</div>

ohh.....can it be done using a custom scoring function?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 25, 2016, 7:04am UTC](https://discuss.elastic.co/t/limiting-the-relevancy-score-of-all-the-searched-documents/48123/6 "2016-04-25T07:04:45Z")

</div>

No idea.

But, again, why do you want to do this? Scoring is relevant to other documents, if you try to force this into a specific range then you are influencing the score and changing your results.

---

<div class="post-metadata">

**Author:** ![divyanshu\_marwah](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@divyanshu\_marwah](https://discuss.elastic.co/u/divyanshu_marwah)\
**Post date:** [April 25, 2016, 7:16am UTC](https://discuss.elastic.co/t/limiting-the-relevancy-score-of-all-the-searched-documents/48123/7 "2016-04-25T07:16:24Z")

</div>

as per the requirements of the project, recommendations are to be made based on the score. And all the matched documents scores are to be displayed which should be in some proper range.

---

<div class="post-metadata">

**Author:** ![rpsandiford](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rpsandiford/32/2206_2.png) [@rpsandiford](https://discuss.elastic.co/u/rpsandiford)\
**Post date:** [April 25, 2016, 12:33pm UTC](https://discuss.elastic.co/t/limiting-the-relevancy-score-of-all-the-searched-documents/48123/8 "2016-04-25T12:33:51Z")

</div>

I think you would end up with false relevance values.

Suppose, against the same index, you run 2 searches. The range of relevance scores from the first search range from .0001 through 1.5000, and you scale that so that it's between 0 and 1. For the second search, suppose the relevance score range is between 0.0500 and 3.5000, and you scale that from 0 through 1. Now you have two result sets – and you might think that the highest scored result from each of the searches, now having a relevance score of 1, have the same value – but they don't. You have artificially scaled your two individual result set relevance ranges into the same 0..1 range. You've lost the original relative scorings that would let you actually compare the top result of each of the searches, because the scaling you apply to get rankings between 0 and 1 isn't constant across all searches.

Bob Sandiford | Principal Engineer | SirsiDynix

---

<div class="post-metadata">

**Author:** ![Bruce\_Ritchie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bruce_ritchie/32/9370_2.png) [@Bruce\_Ritchie](https://discuss.elastic.co/u/Bruce_Ritchie)\
**Post date:** [April 25, 2016, 1:57pm UTC](https://discuss.elastic.co/t/limiting-the-relevancy-score-of-all-the-searched-documents/48123/9 "2016-04-25T13:57:28Z")

</div>

The project requirements are bogus. I've seen this in the past where project managers push for consistent scoring between 0 and 1. You just need to tell them that isn't how it works and forcing it to work (scaling) will result in poor search result ordering.

---

<div class="post-metadata">

**Author:** ![softwaredoug](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/softwaredoug/32/22681_2.png) [@softwaredoug](https://discuss.elastic.co/u/softwaredoug)\
**Post date:** [April 25, 2016, 3:13pm UTC](https://discuss.elastic.co/t/limiting-the-relevancy-score-of-all-the-searched-documents/48123/10 "2016-04-25T15:13:43Z")

</div>

You could divide every score by the max score, outside the search engine. But scores won't be comparable search to search.

But generally these are bogus requirements. You can tell them the author of ["Relevant Search"](http://manning.com/turnbull) said that :-p. Here's a couple of primers on relevance scoring

- Search engine scoring is based on TF\*IDF, which is documented thoroughly in [these Java docs](https://lucene.apache.org/core/4_0_0/core/org/apache/lucene/search/similarities/TFIDFSimilarity.html)
- Pretty soon, I believe starting in Elasticsearch 5.0, [BM25](http://opensourceconnections.com/blog/2015/10/16/bm25-the-next-generation-of-lucene-relevation/) will be the default.
- Relevance scores between fields are [not comparable](http://opensourceconnections.com/blog/2013/07/02/getting-dissed-by-dismax-why-your-incorrect-assumptions-about-dismax-are-hurting-search-relevancy/)

Hope that helps

---

<div class="post-metadata">

**Author:** ![pickypg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pickypg/32/62409_2.png) [@pickypg](https://discuss.elastic.co/u/pickypg)\
**Post date:** [April 25, 2016, 7:44pm UTC](https://discuss.elastic.co/t/limiting-the-relevancy-score-of-all-the-searched-documents/48123/11 "2016-04-25T19:44:04Z")

</div>

> [@softwaredoug](#):
>
> Pretty soon, I believe starting in Elasticsearch 5.0, BM25 will be the default.

Yep, starting in 5.0.

---

<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 5, 2017, 10:56pm UTC](https://discuss.elastic.co/t/limiting-the-relevancy-score-of-all-the-searched-documents/48123/12 "2017-07-05T22:56:26Z")

</div>


