Skip to content

No way to set stored_fields to the string _none_ using the Java API client #680

@davechallis

Description

@davechallis

Java API client version

8.9.1

Java version

17

Elasticsearch Version

8.10.2

Problem description

Elasticsearch allows stored fields to be disabled entirely by setting "stored_fields": "_none_" in search requests (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html#disable-stored-fields).

There's no way to set this using the Java API client however, as the builders (and the JSON the Java API client generates) always generate a list of strings for the stored_fields parameter.

If a request is created from JSON directly, using e.g.:

var req = new SearchRequest.Builder()
    .withJson(new StringReader(
        "{\"stored_fields\": \"_none_\"}"
    ));

when that search is sent, the Java API client generates JSON containing:

{"stored_fields": ["_none_"]}

This then causes a null pointer exception when the request is actually sent:

Cannot invoke "java.util.List.size()" because the return value of "org.elasticsearch.search.fetch.StoredFieldsContext.fieldNames()" is null

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions