# Need help regarding relevancy score sorting in elastic search

**URL:** <https://discuss.elastic.co/t/need-help-regarding-relevancy-score-sorting-in-elastic-search/261361>\
**Category:** Elasticsearch\
**Created:** [January 17, 2021, 9:57pm UTC](https://discuss.elastic.co/t/need-help-regarding-relevancy-score-sorting-in-elastic-search/261361 "2021-01-17T21:57:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Soumya\_Ranjan\_Sahoo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/soumya_ranjan_sahoo/32/80831_2.png) [@Soumya\_Ranjan\_Sahoo](https://discuss.elastic.co/u/Soumya_Ranjan_Sahoo)\
**Post date:** [January 17, 2021, 9:57pm UTC](https://discuss.elastic.co/t/need-help-regarding-relevancy-score-sorting-in-elastic-search/261361/1 "2021-01-17T21:57:25Z")

</div>

```auto

### Settings for Indexing ###

import requests
import json 
import logging
settings = {
    'settings': {
        'index': {
            'number_of_shards': 1,
            'number_of_replicas': 1,
    
            
            'similarity': {
                'default': {
                    'type': 'BM25',
                    "b": 0.3,
                    "k1": 0
                }
            }
        }
    },
    
    'mappings': {
       
            'properties': {
                'title': {
                    'type': 'text',
                }
            }
        }
    
}
headers = {'Content-Type': 'application/json'}
response = requests.put('http://localhost:9200/alldocs', data=json.dumps(settings), headers=headers)
response.json()

```

I am using the above elastic index setting for my search. I am using the BM25 scoring measure here.

Apparently, when I search for the top 20 results, the scores are not sorted. Furthermore, I also see that certain documents that are not in my top-20 results, by means of random sampling, have a better BM25 score (used a different BM25 library).

Can anyone help me figure why is this behavior and how can I resolve this? (Elasticsearch documentation says it sorts all the scores by default)

Could it be because of sharding? But then I have explicitly asked the engine to use a single shard 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:** [February 14, 2021, 9:57pm UTC](https://discuss.elastic.co/t/need-help-regarding-relevancy-score-sorting-in-elastic-search/261361/2 "2021-02-14T21:57:26Z")

</div>

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