Hello,

I am actually fetching the object from ES before,  modifing and updating 
back. I tried updating an object as String with json content or as 
XContent. Neither of these works. My complex json object I am trying to 
update follows:

{
  "adresaId": "adfasfa-5-faa",
  "souradnice": {
    "longitude": 0,
    "latitude": 0,
    "geopoint": [
      0.0,
      0.0
    ]
  },
  "mesto": "adfasfa 5",
  "mestoComplete": "adfasfa 5",
  "ulice": "faa",
  "uliceComplete": "faa",
  "cisloPopisne": 12,
  "cisloOrientacni": 0,
  "adresaComplete": [
    "adfasfa 5 faa",
    "faa adfasfa 5",
    "adfasfa 5 faa",
    "faa adfasfa 5"
  ],
  "adresaCompleteness": "MESTO_ULICE"
}

This content I am trying to update under field in main json document.



On Wednesday, 4 March 2015 15:35:42 UTC+1, Sávio Salvarino Teles de 
Oliveira wrote:
>
> Is the json object correct? Print it here please.
>
> 2015-03-04 7:56 GMT-03:00 Jakub Stransky <[email protected] <javascript:>
> >:
>
>> 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] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/elasticsearch/b4f0e31f-3016-4a96-af9d-c9bf4d2bcfef%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/elasticsearch/b4f0e31f-3016-4a96-af9d-c9bf4d2bcfef%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Regards,
>
> Sávio S. Teles de Oliveira
>
> Co-Founder & Software Engineer at www.gogeo.io. 
> PHD student in Computer Science focusing on High Performance Maps Platform 
> and Spatial Algorithms.
> voice: +55 62 9136 6996
> http://br.linkedin.com/in/savioteles
> https://twitter.com/savioteless
>  

-- 
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/b2c74023-30ee-4ce8-9a59-3b5c21e74459%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to