I am migrating a java application from elastic search high level client to java api client. There is a SearchSourceBuilder class in elastic search java high level client. But I couldn't find any corresponding class in java api client. Can someone help on this? Old code snippet is as below.

BoolQuery.Builder builder = QueryBuilders.bool(); SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); sourceBuilder.query(boolQueryBuilder); 
2

1 Answer

You can write bool query as shown below in new Java client. as far as i know SearchSourceBuilder is not available in new client.

Query termQuery = TermQuery.of(t -> t.field("field_name").value("search_value"))._toQuery(); SearchRequest sr = SearchRequest.of(r -> r.query(q -> q.bool(b -> b.must(termQuery)))); 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.