ElasticSearch 8.1.1 Java API - Sort doesn't work

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:

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

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.

Elasticsearch 6.8 is 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: )

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