# Filter search documents by score

**URL:** <https://discuss.elastic.co/t/filter-search-documents-by-score/66327>\
**Category:** Elasticsearch\
**Created:** [November 17, 2016, 5:25am UTC](https://discuss.elastic.co/t/filter-search-documents-by-score/66327 "2016-11-17T05:25:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roshan\_Bade](https://avatars.discourse-cdn.com/v4/letter/r/ea5d25/32.png) [@Roshan\_Bade](https://discuss.elastic.co/u/Roshan_Bade)\
**Post date:** [November 17, 2016, 5:25am UTC](https://discuss.elastic.co/t/filter-search-documents-by-score/66327/1 "2016-11-17T05:25:05Z")

</div>

I want to filter search results of documents by their score to some limit. How can i get maximum and minimum scores of search results? How can i implements logic in query?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 17, 2016, 6:47am UTC](https://discuss.elastic.co/t/filter-search-documents-by-score/66327/2 "2016-11-17T06:47:27Z")

</div>

The score is somewhat relative.  
Not sure I understand the use case here and if the path you are taking is the best option to solve that.

In terms of score, the maximum is given back as part of the response. The minimum is unknown in the response.

---

<div class="post-metadata">

**Author:** ![Roshan\_Bade](https://avatars.discourse-cdn.com/v4/letter/r/ea5d25/32.png) [@Roshan\_Bade](https://discuss.elastic.co/u/Roshan_Bade)\
**Post date:** [November 30, 2016, 6:00am UTC](https://discuss.elastic.co/t/filter-search-documents-by-score/66327/3 "2016-11-30T06:00:29Z")

</div>

use case:  
I have 23 documents. So i have to include in result the top 80% documents with highest scores. How can we do this?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 30, 2016, 7:34am UTC](https://discuss.elastic.co/t/filter-search-documents-by-score/66327/4 "2016-11-30T07:34:29Z")

</div>

Documents are ordered by score.

---

<div class="post-metadata">

**Author:** ![Roshan\_Bade](https://avatars.discourse-cdn.com/v4/letter/r/ea5d25/32.png) [@Roshan\_Bade](https://discuss.elastic.co/u/Roshan_Bade)\
**Post date:** [November 30, 2016, 7:53am UTC](https://discuss.elastic.co/t/filter-search-documents-by-score/66327/5 "2016-11-30T07:53:40Z")

</div>

yes but i need to show only top 80% of the total results returned which have highest scores.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 30, 2016, 8:17am UTC](https://discuss.elastic.co/t/filter-search-documents-by-score/66327/6 "2016-11-30T08:17:02Z")

</div>

So you have 100 documents which are matching your query. You want to return the first 80 docs.  
But if the resultset is 1 000 documents, you want to return the first 800 docs.  
And if the resultset is 1 000 000, you want to return the first 800 000 docs.

Is that what you mean?

If so, there is no direct way for doing that.

You would need to run a first search to get the count, then search again and set `size` to 80% of the total hits up to the maximum default limit which is 10 000 IIRC.

But again, I don't understand the use case. Why do you need to display 80% of the results. Why not 100%?  
Why not using the default pagination elasticsearch is offering.

Are you looking to extract data to create a CSV or something?

---

<div class="post-metadata">

**Author:** ![Roshan\_Bade](https://avatars.discourse-cdn.com/v4/letter/r/ea5d25/32.png) [@Roshan\_Bade](https://discuss.elastic.co/u/Roshan_Bade)\
**Post date:** [November 30, 2016, 11:15am UTC](https://discuss.elastic.co/t/filter-search-documents-by-score/66327/7 "2016-11-30T11:15:07Z")

</div>

i want to remove documents with lowest relavancy in match query. Is there any other way to do this??

Use case:  
Suppose we have :-  
index: office  
doctype: employee  
post(field): Account officer, account manager, accountant, chief acc etc which are different documents.

Now i search "account" in a match query against all the docs in "post" field. Let's say "chief acc" value for "post" field in above doc is 'least relavant'. I want to exclude those very less relavant matches in search results list. I tried by using score of results but i think that is not feasible. Is there any other way to achieve this beside score??

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 30, 2016, 11:31am UTC](https://discuss.elastic.co/t/filter-search-documents-by-score/66327/8 "2016-11-30T11:31:18Z")

</div>

I don't think so. And with the use case you explained I don't believe you should exclude any matching document.

I'd change the way I search to make sure that last doc never comes back or I'd let the user define what is relevant for him and what is not.

---

<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:** [December 28, 2016, 11:31am UTC](https://discuss.elastic.co/t/filter-search-documents-by-score/66327/9 "2016-12-28T11:31:18Z")

</div>

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