elastic/elasticsearch-java

sourcesIncludes and sourcesExcludes is missing on SearchRequest

MehdiBH opened this issue · 2 comments

Description

Hello,
On SearchRequest class we do not have the possibility to define sourceIncludes() and sourceExcludes() like in java class GetRequest.
However the functionality is present in the Elasticsearch documentation : ES documentation

_source_excludes
(Optional, string) A comma-separated list of source fields to exclude from the response.

You can also use this parameter to exclude fields from the subset specified in _source_includes query parameter.

If the _source parameter is false, this parameter is ignored.

_source_includes
(Optional, string) A comma-separated list of source fields to include in the response.

If this parameter is specified, only these source fields are returned. You can exclude fields from this subset using the _source_excludes query parameter.

If the _source parameter is false, this parameter is ignored.

Hello, thank you for reporting this! Currently in the java client those two options are present as part of the source field:

esClient
    .search(s -> s
        .source(so -> so
            .filter(f -> f
                .excludes("field1", "field2")
                .includes("field3")))
    , Object.class);

However I'm not sure why it differs from what the documentation specifies, I'll investigate this.

Here's why: the server accepts both the query parameters (_source_excludes, _source_includes), and the source nested structure in the body to define which fields to exclude from the response. They're equivalent, and the general approach the java client follows when requests have redundant query parameters is to just provide the builders for the body options.