Using sort with elastic request is not returning score in the response

I am using elasticsearch-rest-high-level-client 7.6.2 version to interact with elastic server from my java application.
Now I am planning to use sorting capability in elastic. When I added the sort in the elastic request. I am not getting the scores back in response.
I understood that it is expected behaviour and suggestion is to use


But I am using RestHighLevelClient. with this how can I create the instance of SearchRequestBuilder?
Is there any other alternate solution for this problem?

Wondering if this works?

SearchRequest sr = new SearchRequest();

But I wonder if this is supposed to work (on a mobile now so I can't test it):

new SearchSourceBuilder().setTrackScores(true);

None of these works because method setTrackScores is part of the class SearchRequestBuilder

Try something like this:

SearchResponse response = SearchRequest("test").source(
        new SearchSourceBuilder().query(
                QueryBuilders.matchQuery("foo", "bar")
), RequestOptions.DEFAULT);

Thanks. This worked.

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