Elasticsearch Java API client about source filtering function

Hello,
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()
    .index("idx_name")
    .query(query)
    .source(SourceConfig.of(s -> s.filter(f -> f.includes(List.of("fieldA", "fieldB")))))
    .build();

SourceConfig give access to include and exclude fields.

3 Likes

Thank you for your example.

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