Exception in thread "main" co.elastic.clients.json.JsonpMappingException: Error deserializing co.elastic.clients.elasticsearch.core.UpdateRequest: Unknown field 'details' (JSON path: details) (line no=1, column no=20, offset=19)
at co.elastic.clients.json.ObjectDeserializer.parseUnknownField(ObjectDeserializer.java:233)
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:190)
at co.elastic.clients.util.WithJsonObjectBuilderBase.withJson(WithJsonObjectBuilderBase.java:54)
at co.elastic.clients.json.WithJson.withJson(WithJson.java:57)
at org.example.Main.lambda$main$0(Main.java:39)
at co.elastic.clients.elasticsearch.ElasticsearchClient.update(ElasticsearchClient.java:2218)
at org.example.Main.main(Main.java:39)
can you please help me how to write the update request?
When using .withJson() the client expects the same syntax as the Rest API, so in your case the json containing the update should be wrapped with "doc" as explained in the documentation, which results in json1 being:
This works, however since the java client has its own syntax I'd suggest switching from the json approach to the java client one, by creating a class for the Record and then using that for updates, for example:
esClient.update(u -> u
.index("test-update")
.id("1")
.doc(record)
, Record.class);
Thanks for the reply, i am thinking of implementing generic request, so i can't use dto object class in the request preparation a I have tried withJson u suggested with doc in json
Exception in thread "main" co.elastic.clients.elasticsearch._types.ElasticsearchException: [es/update] failed: [document_missing_exception] [348]: document missing
at co.elastic.clients.transport.ElasticsearchTransportBase.getApiResponse(ElasticsearchTransportBase.java:338)
at co.elastic.clients.transport.ElasticsearchTransportBase.performRequest(ElasticsearchTransportBase.java:140)
at co.elastic.clients.elasticsearch.ElasticsearchClient.update(ElasticsearchClient.java:2201)
at co.elastic.clients.elasticsearch.ElasticsearchClient.update(ElasticsearchClient.java:2218)
at org.example.Main.main(Main.java:49)
I also tried with .doc with and without doc in JSON, getting error as well.
Exception in thread "main" jakarta.json.JsonException: Jackson exception
at co.elastic.clients.json.jackson.JacksonUtils.convertException(JacksonUtils.java:39)
at co.elastic.clients.json.jackson.JacksonJsonpMapper.serialize(JacksonJsonpMapper.java:100)
at co.elastic.clients.json.JsonpUtils.serialize(JsonpUtils.java:219)
at co.elastic.clients.elasticsearch.core.UpdateRequest.serializeInternal(UpdateRequest.java:370)
at co.elastic.clients.elasticsearch.core.UpdateRequest.serialize(UpdateRequest.java:352)
at co.elastic.clients.json.JsonpMapperBase$JsonpSerializableSerializer.serialize(JsonpMapperBase.java:122)
at co.elastic.clients.json.JsonpMapperBase$JsonpSerializableSerializer.serialize(JsonpMapperBase.java:119)
at co.elastic.clients.json.jackson.JacksonJsonpMapper.serialize(JacksonJsonpMapper.java:92)
at co.elastic.clients.transport.ElasticsearchTransportBase.prepareTransportRequest(ElasticsearchTransportBase.java:258)
at co.elastic.clients.transport.ElasticsearchTransportBase.performRequest(ElasticsearchTransportBase.java:134)
at co.elastic.clients.elasticsearch.ElasticsearchClient.update(ElasticsearchClient.java:2201)
at co.elastic.clients.elasticsearch.ElasticsearchClient.update(ElasticsearchClient.java:2218)
at org.example.Main.main(Main.java:49)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: JsonObject (through reference chain: com.google.gson.JsonObject["asString"])
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:402)
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:361)
at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:323)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:778)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:183)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:502)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:341)
at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:3362)
at co.elastic.clients.json.jackson.JacksonJsonpMapper.serialize(JacksonJsonpMapper.java:98)
... 11 more
Caused by: java.lang.UnsupportedOperationException: JsonObject
at com.google.gson.JsonElement.getAsString(JsonElement.java:179)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:688)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:770)
... 16 more
Exception in thread "main" jakarta.json.JsonException: Jackson exception
at co.elastic.clients.json.jackson.JacksonUtils.convertException(JacksonUtils.java:39)
at co.elastic.clients.json.jackson.JacksonJsonpMapper.serialize(JacksonJsonpMapper.java:100)
at co.elastic.clients.json.JsonpUtils.serialize(JsonpUtils.java:219)
at co.elastic.clients.elasticsearch.core.UpdateRequest.serializeInternal(UpdateRequest.java:370)
at co.elastic.clients.elasticsearch.core.UpdateRequest.serialize(UpdateRequest.java:352)
at co.elastic.clients.json.JsonpMapperBase$JsonpSerializableSerializer.serialize(JsonpMapperBase.java:122)
at co.elastic.clients.json.JsonpMapperBase$JsonpSerializableSerializer.serialize(JsonpMapperBase.java:119)
at co.elastic.clients.json.jackson.JacksonJsonpMapper.serialize(JacksonJsonpMapper.java:92)
at co.elastic.clients.transport.ElasticsearchTransportBase.prepareTransportRequest(ElasticsearchTransportBase.java:258)
at co.elastic.clients.transport.ElasticsearchTransportBase.performRequest(ElasticsearchTransportBase.java:134)
at co.elastic.clients.elasticsearch.ElasticsearchClient.update(ElasticsearchClient.java:2201)
at co.elastic.clients.elasticsearch.ElasticsearchClient.update(ElasticsearchClient.java:2218)
at org.example.Main.main(Main.java:49)
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class java.io.StringReader and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:77)
at com.fasterxml.jackson.databind.SerializerProvider.reportBadDefinition(SerializerProvider.java:1330)
at com.fasterxml.jackson.databind.DatabindContext.reportBadDefinition(DatabindContext.java:414)
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:53)
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:30)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider._serialize(DefaultSerializerProvider.java:502)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:341)
at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:3362)
at co.elastic.clients.json.jackson.JacksonJsonpMapper.serialize(JacksonJsonpMapper.java:98)
... 11 more
The json structure I sent you should be fine, the error [document_missing_exception] [348]: document missing simply means that no document with id 348 exists in index searchresources. The id field in the update request must be the same as it was in the original document, so it was either specified at creation, or autogenerated by elasticsearch.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.