Elasticsearch Java API client about source filtering function

I would like to migrate from High Level rest Java to new java api client.
I have old method using the source filtering feature in High level rest java, like

 sourceBuilder.fetchSource(includeFields, excludeFields);

In new java api, I knew the SourceBuilder is not available, but shoud some function be used like fetchSource() function to let me custom return fields of query?

Many thanks.

Hi @cchuang4

You can try this part

SearchRequest searchRequest = new SearchRequest.Builder()
    .source(SourceConfig.of(s -> s.filter(f -> f.includes(List.of("fieldA", "fieldB")))))

SourceConfig give access to include and exclude fields.


Thank you for your example.

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