# ElasticSearch 8.1.1 Java API - Sort doesn't work

**URL:** <https://discuss.elastic.co/t/elasticsearch-8-1-1-java-api-sort-doesnt-work/301003>\
**Category:** Elasticsearch\
**Created:** [March 29, 2022, 7:06pm UTC](https://discuss.elastic.co/t/elasticsearch-8-1-1-java-api-sort-doesnt-work/301003 "2022-03-29T19:06:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![AKDAS\_System](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akdas_system/32/98091_2.png) [@AKDAS\_System](https://discuss.elastic.co/u/AKDAS_System)\
**Post date:** [March 29, 2022, 7:06pm UTC](https://discuss.elastic.co/t/elasticsearch-8-1-1-java-api-sort-doesnt-work/301003/1 "2022-03-29T19:06:19Z")

</div>

Hello, I'm currently in the process of migrating from Elasticsearch 6.8 to the new Java API in 8.1.1. So far everything is going well but the only problem that is left is that adding sort to SearchRequest breaks everything. Here's a snippet:

```auto
SortOptions sort = new SortOptions.Builder().field(f -> f.field("identifier").order(SortOrder.Asc)).build();
SearchResponse<LuceneDocInfo> search = client.search(r -> r
                .index(LuceneSearchUtils.SEARCH_INDEX)
                .from(startFrom)
                .size(pageSize)
                .query(query)
                .sort(sort),
        LuceneDocInfo.class);

```

This then produces an error in the console

```auto
2022-03-29 21:48:58.618 DEBUG 51036 --- [nio-8083-exec-8] org.elasticsearch.client.RestClient : request [POST https://es01:9200/lvm_all_2/_search?typed_keys=true] returned [HTTP/1.1 400 Bad Request]
co.elastic.clients.elasticsearch._types.ElasticsearchException: [es/search] failed: [search_phase_execution_exception] all shards failed
	at co.elastic.clients.transport.rest_client.RestClientTransport.getHighLevelResponse(RestClientTransport.java:281)
	at co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:147)
	at co.elastic.clients.elasticsearch.ElasticsearchClient.search(ElasticsearchClient.java:1526)
	at co.elastic.clients.elasticsearch.ElasticsearchClient.search(ElasticsearchClient.java:1543)
	at lv.autentica.grifs.business.services.search.LuceneSearchService.searchDocIndex(LuceneSearchService.java:345)
...

```

If I remove .sort() everything works perfectly. I couldn't really find an example for a query with sort so maybe I'm doing it wrong. Any advice would be appreciated.

---

<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:** [March 29, 2022, 7:06pm UTC](https://discuss.elastic.co/t/elasticsearch-8-1-1-java-api-sort-doesnt-work/301003/2 "2022-03-29T19:06:19Z")

</div>

Elasticsearch 6.8 is [EOL](https://www.elastic.co/support/eol) and no longer supported. Please upgrade ASAP.

(This is an automated response from your friendly Elastic bot. Please report this post if you have any suggestions or concerns :elasticheart: )

---

<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:** [April 26, 2022, 7:06pm UTC](https://discuss.elastic.co/t/elasticsearch-8-1-1-java-api-sort-doesnt-work/301003/3 "2022-04-26T19:06:24Z")

</div>

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