elasticsearch-java icon indicating copy to clipboard operation
elasticsearch-java copied to clipboard

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

Open davechallis opened this issue 2 years ago • 4 comments

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

davechallis avatar Sep 29 '23 08:09 davechallis

@davechallis did you find a workaround for this issue? I'm facing the same issue and it's a huge performance bottleneck.

valasatava avatar Nov 07 '23 18:11 valasatava

@valasatava afraid not, I had a look through the source, and I don't think it's at all possible with the Java API client. In the end we had to switch to using the low level REST client, and writing our own classes to construct queries.

davechallis avatar Nov 08 '23 09:11 davechallis

Hello! Thank you for reporting this, and sorry for the wait. The problem here is that the java clients defaults to sending stored_fields as an array, while the server seems to only accept a string in this particular case. We'll have to investigate this because it's not really clear whether this is a client or a server problem.

l-trotta avatar Apr 24 '24 08:04 l-trotta

Definitely a bug on our side, will be fixed soon!

l-trotta avatar May 02 '24 10:05 l-trotta

Let me also upvote this issue, it blocks us from moving to the Java API client

akryvko avatar May 16 '24 14:05 akryvko