Individual scores query

Hello,
Our client needs a way to perform a query and extract the results containing not only the score per row, but also the individual scores of each search keyword.
To be more precise, they are performing a query with hundreds of keywords in OR mode. The standard elasticsearch score is used. But they want in the export to have also for each keyword the individual score (as if the search would have been run with only that keyword).
We managed to achieve it by running first the query with all the keywords, and then running again the query for each keyword only for getting the score for it and adding to the export by mapping it to the results of the first query. There is a big performance problem with this solution, so we can't have too many keywords, because each query is taking a few seconds and in the end the operation is taking too long and exceeds our server's timeout (which we already increased…).
From our debugging we understand that what takes the most time is transferring the (big) results of each query from elasticsearch server to our backend. So we think that the best solution would be to have it all extracted in one single query, but we couldn't find a way to do it.
The individual scores are already calculated by elasticsearch cluster when calculating the score (in the end the score is the sum of all the scores), so we would just need a way to have them extracted. Eventually we do don't necessarily need the total score as we could just sum the individual ones…
We've tried the solution purposed Here :

hit.getExplanation().getValue() will give you the score.
As you mentioned hit.getExplanation().getDetails() is itself org.apache.lucene.search.Explanation array. 
You can get the score of all sub-calculations by calling getValue() method.

But the performance it's bad.

The question is: is there a way to have this extracted in a single query?
Thanks!

Hi @Rui_Goncalves

I understand and I think that this solution you shared may be the only way to get the individual score, but maybe Elastic members know a better solution. I'm also curious to know new solutions

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