-
Notifications
You must be signed in to change notification settings - Fork 190
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
[BUG] Deserialization CreateIndexRequest is broken. #206
Comments
Repro steps? Or maybe want to try to write a failing test for this? |
Hi, I haven't found any test template, Here a simple example of the issue:
You should get |
I am getting the same error. Any news on this bug? |
I have created a builder for the builder using the internal Serialiser. If that can help. |
@alexisgayte - sure, can you please share it? |
This is how I have created index using the client. Let me know if this works for you private String getAnomalyDetectorMappings() throws IOException {
URL url = AnomalyDetectionIndices.class.getClassLoader().getResource(<enter json file>);
return Resources.toString(url, Charsets.UTF_8);
}
JsonpMapper mapper = javaClient._transport().jsonpMapper();
JsonParser parser = null;
try {
parser = mapper
.jsonProvider()
.createParser(new ByteArrayInputStream(getAnomalyDetectorMappings().getBytes(StandardCharsets.UTF_8)));
} catch (Exception e) {
e.printStackTrace();
}
CreateIndexRequest request = null;
try {
request = new CreateIndexRequest.Builder()
.index("index_name")
.mappings(TypeMapping._DESERIALIZER.deserialize(parser, mapper))
.build();
} catch (Exception e) {
e.printStackTrace();
} and for handling deserialization using ObjectMapper OpenSearchTransport transport = new RestClientTransport(
restClient,
new JacksonJsonpMapper(new ObjectMapper().registerModule(new JavaTimeModule()))
); |
Yes, that is mainly the idea.
Then you can use it the way you want :
|
@alexisgayte Try to turn this into a failing spec? |
I am not sure what you mean by that, I have done it 3 months ago and moved on, bear with me. The main problem I had, is the definition cannot be auto populated without the index (which is not provided by the opensearch API call and the mapping we get from the API). I am mainly using spring to wrap my object and auto mapping. |
Thanks for sticking around @alexisgayte! The original issue and the example above says "The deserialization of CreateIndexRequest is broken." and your code ends up with a missing required property error. Is it unexpected? What do we want to do in this project about it? |
Yes of course, the property is part of the json. |
What is the bug?
The deserialization of CreateIndexRequest is broken.
How can one reproduce the bug?
By deserializing CreateIndexRequest using the ObjectMapper provided.
What is the expected behavior?
Here, it is unclear what the behaviour should be. however it should not fail.
Do you have any additional context?
The serialization is specific to opensearch client therefore you need to use it. But somehow the "index" field is discarded as it is part of the URL for the API call.
The deserialization follows the same process as the serialization. However, "index" field is mandatory but it cannot be pass as property.
https://github.com/opensearch-project/opensearch-java/blob/main/java-client/src/main/java/org/opensearch/client/opensearch/indices/CreateIndexRequest.java#L440-L446
https://github.com/opensearch-project/opensearch-java/blob/main/java-client/src/main/java/org/opensearch/client/opensearch/indices/CreateIndexRequest.java#L97
The text was updated successfully, but these errors were encountered: