Elasticsearch Client new version 8.1 how to request a search

Viewed 126

Just struggelin with the new Elastic version 8.1 cause have no idea how to migrate a simple serch into the new api:

The old approach:

...    
final BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must(QueryBuilders.matchQuery("name", "Paul"));

final SearchRequest searchRequest = new SearchRequest("/myIndex");
searchRequest.searchType(SearchType.DEFAULT).source(searchSourceBuilder);
final SearchResponse sr = client.search(searchRequest, RequestOptions.DEFAULT);
...

This was straight forward. Could find out the hits etc. from the response and everything worked fine.

But with the new approach i cannot handle the searchrequest as it was before:

final SearchResponse<TDocument> sr1 = client.search(searchRequest, Class<TDocument> tDocumentClass);

For what is the TDocument type needed and how to define my model that it will fit into the API?

0 Answers
Related