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

**URL:** <https://discuss.elastic.co/t/what-is-the-replacment-for-highlevelrestclient-searchhit-getsortvalues-in-the-java-api-client/332676>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [May 5, 2023, 6:24pm UTC](https://discuss.elastic.co/t/what-is-the-replacment-for-highlevelrestclient-searchhit-getsortvalues-in-the-java-api-client/332676 "2023-05-05T18:24:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kayld](https://avatars.discourse-cdn.com/v4/letter/k/9e8a1a/32.png) [@kayld](https://discuss.elastic.co/u/kayld)\
**Post date:** [May 5, 2023, 6:24pm UTC](https://discuss.elastic.co/t/what-is-the-replacment-for-highlevelrestclient-searchhit-getsortvalues-in-the-java-api-client/332676/1 "2023-05-05T18:24:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [May 5, 2023, 7:43pm UTC](https://discuss.elastic.co/t/what-is-the-replacment-for-highlevelrestclient-searchhit-getsortvalues-in-the-java-api-client/332676/2 "2023-05-05T19:43:09Z")

</div>

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);
});

```

---

<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:** [June 2, 2023, 7:43pm UTC](https://discuss.elastic.co/t/what-is-the-replacment-for-highlevelrestclient-searchhit-getsortvalues-in-the-java-api-client/332676/3 "2023-06-02T19:43:50Z")

</div>

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