# Preserving Inner Objects During Re-Index of Parent Document

**URL:** https://discuss.elastic.co/t/preserving-inner-objects-during-re-index-of-parent-document/12520
**Category:** Elasticsearch
**Created:** [June 22, 2013, 3:22pm UTC](https://discuss.elastic.co/t/preserving-inner-objects-during-re-index-of-parent-document/12520 "2013-06-22T15:22:45Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Nariman\_Haghighi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nariman_haghighi/32/1065_2.png) [@Nariman\_Haghighi](https://discuss.elastic.co/u/Nariman_Haghighi)
#### Post date: [June 22, 2013, 3:22pm UTC](https://discuss.elastic.co/t/preserving-inner-objects-during-re-index-of-parent-document/12520/1 "2013-06-22T15:22:45Z")

</div>

We have a JSON document (Media) that has two inner objects (GeoCodeResult  
and LocalTime).

We first index the Media document and then rely on secondary background  
processes to populate the two inner objects separately.

We need the three to be combined into a single ES type for performance  
reasons.

The Media documents are re-indexed from their original source from time to  
time, and when this happens the two inner objects that were previously  
populated are reset back to null.

Is it possible to update the Media documents while preserving the two inner  
objects?

I'm picturing something like an update script that can be provided to the  
index operation that preserves the two inner objects unless non-null values  
are found in the new parent document.

--  
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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Nariman\_Haghighi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nariman_haghighi/32/1065_2.png) [@Nariman\_Haghighi](https://discuss.elastic.co/u/Nariman_Haghighi)
#### Post date: [June 23, 2013, 2:50pm UTC](https://discuss.elastic.co/t/preserving-inner-objects-during-re-index-of-parent-document/12520/2 "2013-06-23T14:50:20Z")

</div>

Seems like this is now supported via bulk partial updates using the upsert  
scripts:

Partial updates and nested types:  
[http://elasticsearch-users.115913.n3.nabble.com/partial-update-and-nested-type-td3959065.html](http://elasticsearch-users.115913.n3.nabble.com/partial-update-and-nested-type-td3959065.html)

Added support for the update operation in the bulk api:

> <https://github.com/elastic/elasticsearch/commit/9ddd675a02431a72daf48da991ce7eda726f1c79>
>
> Update requests can now be put in the bulk api. All update request options are s…upported.
> 
> Example usage:
> \`\`\`
> curl -XPOST 'localhost:9200/\_bulk' --date-binary @bulk.json
> \`\`\`
> 
> Contents of bulk.json that contains two update request items:
> \`\`\`
> { "update" : {"\_id" : "1", "\_type" : "type1", "\_index" : "index1", "\_retry\_on\_conflict" : 3} }
> { "doc" : {"field" : "value"} }
> { "update" : { "\_id" : "0", "\_type" : "type1", "\_index" : "index1", "\_retry\_on\_conflict" : 3} }
> { "script" : "counter += param1", "lang" : "js", "params" : {"param1" : 1}, "upsert" : {"counter" : 1}}
> \`\`\`
> The \`doc\`, \`upsert\` and all script related options are part of the payload. The \`retry\_on\_conflict\` option is part of the header.
> 
> Closes #2982

Is this correct? How does this approach perform in comparison to the  
standard index API call?

On Saturday, June 22, 2013 11:22:45 AM UTC-4, Nariman Haghighi wrote:

> We have a JSON document (Media) that has two inner objects (GeoCodeResult  
> and LocalTime).
> 
> We first index the Media document and then rely on secondary background  
> processes to populate the two inner objects separately.
> 
> We need the three to be combined into a single ES type for performance  
> reasons.
> 
> The Media documents are re-indexed from their original source from time to  
> time, and when this happens the two inner objects that were previously  
> populated are reset back to null.
> 
> Is it possible to update the Media documents while preserving the two  
> inner objects?
> 
> I'm picturing something like an update script that can be provided to the  
> index operation that preserves the two inner objects unless non-null values  
> are found in the new parent document.

--  
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 [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [July 6, 2017, 2:29am UTC](https://discuss.elastic.co/t/preserving-inner-objects-during-re-index-of-parent-document/12520/3 "2017-07-06T02:29:53Z")

</div>


