Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
davechallis opened this issue Sep 29, 2023 · 6 comments
Closed
Labels
Area: Generator Category: Bug Something isn't working

Comments

@davechallis
Copy link

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
@valasatava
Copy link

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

@davechallis
Copy link
Author

@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.

@l-trotta
Copy link
Contributor

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
Copy link
Contributor

l-trotta commented May 2, 2024

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

@l-trotta l-trotta added Category: Bug Something isn't working and removed need-more-info labels May 2, 2024
@akryvko
Copy link

akryvko commented May 16, 2024

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

@l-trotta
Copy link
Contributor

fixed in the code generator, will be part of the next release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Generator Category: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants