Filter search documents by score


(Roshan Bade) #1

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?


(David Pilato) #2

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.


(Roshan Bade) #3

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?


(David Pilato) #4

Documents are ordered by score.


(Roshan Bade) #5

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


(David Pilato) #6

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?


(Roshan Bade) #7

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??


(David Pilato) #8

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.


(system) #9

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