# ES Upserts for child doc types doesn't set the parent - Bug

**URL:** https://discuss.elastic.co/t/es-upserts-for-child-doc-types-doesnt-set-the-parent-bug/23908
**Category:** Elasticsearch
**Created:** [June 18, 2015, 12:38pm UTC](https://discuss.elastic.co/t/es-upserts-for-child-doc-types-doesnt-set-the-parent-bug/23908 "2015-06-18T12:38:31Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![suman\_reddy\_aella](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@suman\_reddy\_aella](https://discuss.elastic.co/u/suman_reddy_aella)
#### Post date: [June 18, 2015, 12:38pm UTC](https://discuss.elastic.co/t/es-upserts-for-child-doc-types-doesnt-set-the-parent-bug/23908/1 "2015-06-18T12:38:31Z")

</div>

Hi,

I am using the ES 1.4.2 version and associated Java API. I see bug with ES for the **Upsert** script.

**The Upsert operation is unable to set "\_parent" for Child doc types.**

Here I use the below **Upsert** script for inserting/updating the child doc of type " **tag**". The " **tag**" mapping has the parent " **userinfo**" mapping. I use " **userId**" in " **UserInfo**" mapping as its " **\_id**". The " **tag**" type uses the same as " **\_parent**".

```
    XContentBuilder builder = XContentFactory.jsonBuilder().startObject()
                    .field("eventDate", sdf.format(tagObj.getEventDate()))
                    .field("manufacturer", tagObj.getManufacturer())
                    .field("applicationId", tagObj.getApplicationId())
                    .field("count", tagObj.getEventCount())
                    .field("tag", tagObj.getEventName())
                    .endObject();
            logger.info("About to insert/update index for tag :" + builder.string());
           
            bulkBuilder.add(esClient
                    .prepareUpdate("users", "tag", tagObj.getId())
                    .setScript("ctx._source.eventDate = \""+sdf.format(tagObj.getEventDate())
                                    +"\";ctx._source.count += "+tagObj.getEventCount()
                                    +";ctx._source.country = \""+tagObj.getCountry()+"\"")
                     .setUpsert(builder)
                    .setParent(Long.toString(tagObj.getUserId()))
                    .setRouting(Long.toString(tagObj.getUserId())));

```

Here this **Upsert** script inserts the " **tag**" doc but doesn't set the " **\_parent"** field.

The same was working with the Insert script given below. The " **\_parent**" was getting set in " **tag**" doc.

```
    bulkBuilder.add(esClient.prepareIndex("users", "tag", tagObj.getId())
.setSource(builder.string())
.setParent(Long.toString(tagObj.getUserId()))
.setRouting(Long.toString(tagObj.getUserId())));

```

Why is the **Upsert** operation having this issue.

Thanks  
Suman

---

<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, 12:06am UTC](https://discuss.elastic.co/t/es-upserts-for-child-doc-types-doesnt-set-the-parent-bug/23908/2 "2017-07-06T00:06:12Z")

</div>


