Java api : how to append/add a object to array using java highlevel client

I've nested type in mappings and below doc looks like
{
"id" : 1,
"blog": "something.."
users : [
{ "name","xyz",
"id": 123
},
{ "name","abc",
"id": 235
}

]

I want to add one more user to users array how to do that ?

https://www.elastic.co/guide/en/elasticsearch/client/java-api/6.5/java-docs-update.html

I required equivalent java code to perform below request using HighLevelRestClient and UpdateRequest

curl -X POST "localhost:9200/test/_doc/1/_update" -H 'Content-Type: application/json' -d'

{
"script" : {
"source": "ctx._source.tags.add(params.tag)",
"lang": "painless",
"params" : {
"tag" : "blue"
}
}
}
'

You probably want to read https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-update-by-query.html

I didn't see example adding one more object to array

I just answered to your question:

I required equivalent java code to perform below request using HighLevelRestClient and UpdateRequest

I did not mean to answer to "How to add one more user to users array?" question. I thought you solved it with the curl script you shared.

curl is working.. i'm using (java highlevelrestclient)

compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:6.5.4'

i didn't see any example java client

You probably need to upgrade. I'm not sure the method I pasted the documentation for is available with your version.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.