-
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
When deserializing to SearchResponse<JsonData> getting error for suggest field #1024
Comments
Want to turn this into a (failing) unit test? |
This is not the only place where serialization is not happening properly. |
@AayushiJain012 You're absolutely right, all these instances need to be fixed :( We have recently merged a beginning of a code generator that aims to resolve this entire class of problems (#366). There are a few things you can do to help:
The combination will ensure that as we switch to the generator we're not introducing regressions. |
I dont understand how the changes you have mentioned is related to the problem I am facing. I am talking about this serialize method |
Generally these problems are trying to deserialize something that's the wrong type in code vs. the response. Start by writing a unit test for this problem, should point exactly to the field that is the issue. |
The problem is with serialize method not properly serializing suggest and nested-aggregation Can you help me with the logic how to correctly serialize search response in Java client |
Probably. Write a failing unit test for it? @Xtansia can point you to something similar. |
The failure is happening here: https://github.com/opensearch-project/opensearch-java/blob/main/java-client/src/main/java/org/opensearch/client/json/ExternallyTaggedUnion.java#L150-L152 It's missing the check from this other path: https://github.com/opensearch-project/opensearch-java/blob/main/java-client/src/main/java/org/opensearch/client/json/ExternallyTaggedUnion.java#L126-L131 Which is to say, you need to enable |
I am using client.search() Line 293 in 13982b1
|
@AayushiJain012 I see, that is a problem types should be able to round-trip if they implement both serialize & deserialize. However, could you please explain a bit your use case for why you need to re-serialize & deserialize the response object rather than using it directly or mapping into your own object structure? |
@Xtansia We are getting the response as JsonData and then serializing it to store in cache. For second request if data is in cache we simply deserialize it and send back, instead of making call to opensearch. |
Would love a PR that fixes the serialization issue. |
who will work on that PR and in when we can get the fix? |
Nobody is working on it right now. Maybe you? |
What is the bug?
While trying to deserialize this response I am getting StringOutofBoundException
Response -
{"took":4,"timed_out":false,"_shards":{"failed":0.0,"successful":1.0,"total":1.0,"skipped":0.0},"hits":{"total":{"relation":"eq","value":0},"hits":[]},"aggregations":{"cardinality#itemCount":{"value":0}},"suggest":{"correction":[{"length":5,"offset":0,"text":"talbe","options":[{"text":"table","freq":22,"score":0.8}]}]}}
Exception -
java.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 10
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:4608)
at java.base/java.lang.String.substring(String.java:2711)
at org.opensearch.client.json.ExternallyTaggedUnion.lambda$arrayDeserializer$0(ExternallyTaggedUnion.java:152)
at org.opensearch.client.json.JsonpDeserializer$3.deserialize(JsonpDeserializer.java:138)
at org.opensearch.client.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:87)
at org.opensearch.client.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:81)
at org.opensearch.client.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:185)
at org.opensearch.client.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:146)
at org.opensearch.client.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:87)
at org.opensearch.client.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:91)
Method to deserialize -
**Method used to serialize - **
How can one reproduce the bug?
Create a request with suggester, serialize the response and then deserialize it.
What is the expected behavior?
No Error and get deserialized response
What is your host/environment?
Operating system, version.
Do you have any screenshots?
If applicable, add screenshots to help explain your problem.
Do you have any additional context?
Java client version - 2.10.2
The text was updated successfully, but these errors were encountered: