What is the replacment for HighLevelRestClient SearchHit.getSortValues() in the Java API Client?

The HighLevelRestClient has a method in SearchHit class called getSortValues(). In converting to the Java API Client I cannot find a replacement or way to get the same information. How would I go about getting the sort value information?

Hi @kayld

In this example you can access sort values. I did a search by movie title and sort by _score and rating. After I have access to sortValues here: hit.sort().

SearchRequest request = new SearchRequest.Builder().index("idx_movies")
    .query(new Query.Builder().match(new MatchQuery.Builder().field("title").query("batman").build()).build())
    .sort(SortOptions.of(so -> so
            .field(FieldSort.of(fs -> fs
                .field("_score").order(SortOrder.Desc)))),
        SortOptions.of(so -> so
            .field(FieldSort.of(fs -> fs
                .field("rating").order(SortOrder.Desc))))
    )
    .build();
SearchResponse<Movie> response = ClientUtils.getClient().search(request, Movie.class);
response.hits().hits().forEach(hit -> {
  var sortValues = hit.sort(); //<--- sort values here
  var output = String.format("Doc ID: %s - Sort: _score=%s rating=%s", hit.id(), sortValues.get(0), sortValues.get(1));
  System.out.println(output);
});

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