Hello,

I am new to elasticsearch and I am trying to update just a portion of the 
document via java api. From the rest client e.g. I am successfull but I am 
really struggling with java api - UpdateRequest. I am updating a second 
level source field with a "json object".

POST /ho/B/3278778460/_update{
    "script":"ctx._source.adresa = upd_adr",    
    "params":{
        "upd_adr" :{ some_json }        
    }}

This works fine and "some_json" is updated correctly at correct possition 
etc. However when I tried the same in java/scala

val json_adresa = "{ some_json}"

val ss = XContentFactory.jsonBuilder()
val x = XContentFactory.xContent(XContentType.JSON).createParser(json_adresa)
ss.field(address_key).copyCurrentStructure(x)
x.close()

val i = new UpdateRequest(storage_folder,"BYT",adId)
    i.script("ctx._source.adresa = upd_adr")
    i.addScriptParam("upd_adr",ss)
    
.. and then send it to update API

I am getting following error:

Caused by: java.io.IOException: Can't write type [class 
org.elasticsearch.common.xcontent.XContentBuilder]
        at 
org.elasticsearch.common.io.stream.StreamOutput.writeGenericValue(StreamOutput.java:407)
        at 
org.elasticsearch.common.io.stream.StreamOutput.writeGenericValue(StreamOutput.java:374)
        at 
org.elasticsearch.common.io.stream.StreamOutput.writeMap(StreamOutput.java:319)
        at 
org.elasticsearch.action.update.UpdateRequest.writeTo(UpdateRequest.java:662)
        at 
org.elasticsearch.transport.netty.NettyTransport.sendRequest(NettyTransport.java:601)
        at 
org.elasticsearch.transport.TransportService.sendRequest(TransportService.java:206)
        ... 26 more


Can someone more experienced help?

Thanks a lot
Jakub


-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/b4f0e31f-3016-4a96-af9d-c9bf4d2bcfef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to