javaelasticsearchapiclient

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);

Solution

  • 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))));