Partial update/add/delete of a document using java

I would like to add/update/delete nested documents in java. If there is example can someone point me that please.

Is it done only through scripts or there are api's to do dthat.

Index API: https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-index.html

sorry i am not getting your point, i want to do CUD on nested objects. Can you provide the section that is relevant please

You can't do that just on a nested object. You need to index the full document again.
If I still don't understand your question please add an example using the REST API and we'll see how to translate it to Java.

Any change to a nested document requires the full document to be reindexed, which can get expensive for large documents that are frequently updated. You can push the creation of the document to the server through a scripted update or retrieve it and perform the change yourself in the client.

In below mapping, i have a nestedDocument named allImageReco, is there a way to add/update/delete those nested document. I read somewhere these partial updates doesnt go through the whole document re-indexing.

mappings": {
"jobupdate": {
"properties": {
"advisoryDescription": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"allImageReco": {
"type": "nested",
"include_in_parent": true,
"properties": {
"advisoryId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"advisoryType": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"platform": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"recommendedImage": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}

        }
      } ...

i tried this curl post using kibana,
POST cisco_nia-eventagg/jobupdate/JS23EmkBPgJ20mqE2WE1/_update
{
"script" : {
"source":"ctx._source.allImageReco.add(params.newElement)",
"params": {
"newElement": {
"yes" : 121,
"yes1" : 1469050965
}
}}
}

it seems to work, not sure, if it re-indexes whole document. But couldnt translate to java though

This is incorrect. The full document is always reindexed. This typically means nested documents are very well suited to query heavy use-cases with relatively few updates. If you on the other hand are trying to constantly add to it and expect the number of nested documents to become large, it is likely to eventually become a bottleneck as each nested document is indexed as a separate document behind the scenes in Elasticsearch.

How large are you nested documents likely to be? How frequently will you be updating each one?

1 Like

Thank you!!, so i can read the document and make amends and then update the document or use the scripts to update either way it will re-index the whole document -- correct. I am not expecting to grow, but there may be updates to it, frequently

How large are the documents likely to be? How many nested sub-documents? What is the use-case?

Documents are device related and there are 2 nested structures. use-case is get the device related data. Also, how to convert this curl to java
POST cisco_nia-eventagg/jobupdate/JS23EmkBPgJ20mqE2WE1/_update
{
"script" : {
"source":"ctx._source.allImageReco.add(params.newElement)",
"params": {
"newElement": {
"yes" : 121,
"yes1" : 1469050965
}
}}
}

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