Replacement for Searchsourcebuilder Class in Java Api Client

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

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.

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest