No way to set `stored_fields` to the string `_none_` using the Java API client
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 did you find a workaround for this issue? I'm facing the same issue and it's a huge performance bottleneck.
@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.
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.
Definitely a bug on our side, will be fixed soon!
Let me also upvote this issue, it blocks us from moving to the Java API client