-
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] OpenSearchException: Request failed: [mapper_parsing_exception] failed to parse #362
Comments
This is similar to #297 and there's some hints on how to do that in #297 (comment). I don't have working code to share though, let's try and work through it? Maybe @owaiskazi19 or @Xtansia have an example? Elasticsearch-java has since added a Finally, maybe make a sample ala https://github.com/dblock/opensearch-java-client-demo in Scala, so we have something to start with? |
Thanks @dblock for the quick response, I tried based on the hints, and I could add a document and query it. Here's a demo project in Scala: https://github.com/yash025/opensearch-scala-demo |
Awesome, thanks @yash025. So you have a document type and you serialize it to JSON with |
Based on this test case https://github.com/opensearch-project/opensearch-java/blob/main/java-client/src/test/java/org/opensearch/client/opensearch/json/JsonDataTest.java#L51-L63 I think the correct way to get from a JSON string to a JsonpMapper mapper = openSearchClient._transport().jsonpMapper();
JsonParser parser = mapper.jsonProvider().createParser(new StringReader(jsonString));
JsonData data = JsonData.from(parser, mapper); |
I think this is a feature request to add |
@dblock I will try to squeeze in some time this week and try this. |
@dblock Question, What should be the TDocument for withJson? Should we create some class similar to CirceToJava something like RawJson and whenever someone wants to use raw json as the document, then that will be TDocument I mean it'll be the type of IndexRequest(IndexRequest[RawJson])? I don't see much use of withJson in the java world, and I did check withJson in the latest version of elastic search java client it won't work for complex json they've written some simple JSON mapper which will try to deserialize that back to TDocument ignoring unknown fields, for complex json(multi nested) user need to specify the parser and mapper explicitly. |
@yash025 I am not sure, but I'm thinking really from the POV of a developer who has a bunch of documents/queries and just wants to make them, without stuffing the JSON into well defined structures. This is particularly useful in |
Hey @yash025! You can refer #257 which has the sample code in Java to create an index. Currently, we don't have private String getAnomalyDetectorMappings() throws IOException {
URL url = AnomalyDetectionIndices.class.getClassLoader().getResource(ANOMALY_DETECTORS_INDEX_MAPPING_FILE);
return Resources.toString(url, Charsets.UTF_8);
}
|
Hi, @owaiskazi19 thanks, I've found a workaround mentioned in the above comment, that works for me. |
@dblock so should I go and add a class similar to CirceToJava something like RawJSON, and whoever wants to use raw json they should use that class |
I think |
Yes, that would look nicer, but we need to provide |
🤔 @yash025 I am not sure. Give it a try? Let's look at code? |
What is the bug?
When we push the document as a JSON string using IndexRequest, the API fails with the below error the same works if we pass the document as a java map.
Caused by: org.opensearch.client.opensearch._types.OpenSearchException: Request failed: [mapper_parsing_exception] failed to parse
at org.opensearch.client.transport.aws.AwsSdk2Transport.parseResponse(AwsSdk2Transport.java:530)
at org.opensearch.client.transport.aws.AwsSdk2Transport.executeSync(AwsSdk2Transport.java:438)
at org.opensearch.client.transport.aws.AwsSdk2Transport.performRequest(AwsSdk2Transport.java:241)
at org.opensearch.client.opensearch.OpenSearchClient.index(OpenSearchClient.java:764)
Are there any working examples where JSON string is pushed as a document instead of java POJOs?
I'm trying this in Scala.
Below code works, where the document is passed as java map to the same index
The text was updated successfully, but these errors were encountered: