Sort in Java API client

Hi Experts,

I am using new java API client to connect with Elasticsearch. My requirement is to search documents in sorted order of given parameters.

I have written the below code to search and sort by "customer".

        SortOptions sort = new SortOptions.Builder().field(f -> f.field("customer").order(SortOrder.Asc)).build();
        List<SortOptions> list = new ArrayList<SortOptions>();

        SearchResponse<Order> response = -> b.index("order").size(100).sort(list)
                .query(q -> q.bool(bq -> bq
                        .filter(fb -> fb.range(r -> r.field("orderTime").
                )), Order.class);

I am getting below Exception.'

Exception in thread "main" 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(
	at co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(
	at model.OrderDAO.fetchRecordsQuery(
	at model.OrderDAO.main(

Same code work if I remove .sort() method.
Please let me know what is wrong with the parameter being passed in .sort() method and help me with the correct syntax for sorting.

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