# Using parent property in update API doesnt seem to work

**URL:** https://discuss.elastic.co/t/using-parent-property-in-update-api-doesnt-seem-to-work/13058
**Category:** Elasticsearch
**Created:** [August 4, 2013, 12:08am UTC](https://discuss.elastic.co/t/using-parent-property-in-update-api-doesnt-seem-to-work/13058 "2013-08-04T00:08:33Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Poorva\_Potnis](https://avatars.discourse-cdn.com/v4/letter/p/e68b1a/32.png) [@Poorva\_Potnis](https://discuss.elastic.co/u/Poorva_Potnis)
#### Post date: [August 4, 2013, 12:08am UTC](https://discuss.elastic.co/t/using-parent-property-in-update-api-doesnt-seem-to-work/13058/1 "2013-08-04T00:08:33Z")

</div>

Hi -

If I try to add a document using the bulk update API (doc\_as\_upsert=true)  
and set its parent property, I do not see the document as the child of the  
specified parent when I make a has\_parent query. Can you please help see  
what could be wrong with the below. Thanks in advance.

Following is the mapping:

mappings: {  
store: {  
properties: {  
name: {  
type: string  
}  
owner: {  
type: string  
}  
}  
}  
department: {  
\_routing: {  
required: true  
}  
properties: {  
name: {  
type: string  
}  
numberOfProducts: {  
type: long  
}  
}  
\_parent: {  
type: store  
}  
}  
}

Following is the bulk input file:

{ "index" : { "\_index" : "parent\_child", "\_type" : "store", "\_id" :  
"store1" } }  
{ "name" : "auchan", "owner" : "chris" }  
{ "index" : { "\_index" : "parent\_child", "\_type" : "department", "\_id" :  
"department1", "parent" : "store1" } }  
{ "name" : "toys", "numberOfProducts" : 150 }  
{ "update" : { "\_index" : "parent\_child", "\_type" : "department", "\_id" :  
"department2", "parent" : "store1" } }  
{"doc" : { "name" : "dolls", "numberOfProducts" : 300 }, "doc\_as\_upsert" :  
"true"}

Query -

{  
"query": {  
"has\_parent": {  
"type": "store",  
"query": {  
"match\_all": {}  
}  
}  
}  
}

--  
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: ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)
#### Post date: [August 5, 2013, 2:34pm UTC](https://discuss.elastic.co/t/using-parent-property-in-update-api-doesnt-seem-to-work/13058/2 "2013-08-05T14:34:59Z")

</div>

Hi Poorva,  
you are right, I looked into it and this is most likely a bug. It seems  
that we do read the parent, but we only use it for routing when updating a  
document, while in case of doc\_as\_upsert we should also add the \_parent to  
the documents. Would you mind opening an issue here[https://github.com/elasticsearch/elasticsearch/issues](https://github.com/elasticsearch/elasticsearch/issues)  
?

On Sunday, August 4, 2013 2:08:33 AM UTC+2, Poorva Potnis wrote:

> Hi -
> 
> If I try to add a document using the bulk update API (doc\_as\_upsert=true)  
> and set its parent property, I do not see the document as the child of the  
> specified parent when I make a has\_parent query. Can you please help see  
> what could be wrong with the below. Thanks in advance.
> 
> Following is the mapping:
> 
> mappings: {  
> store: {  
> properties: {  
> name: {  
> type: string  
> }  
> owner: {  
> type: string  
> }  
> }  
> }  
> department: {  
> \_routing: {  
> required: true  
> }  
> properties: {  
> name: {  
> type: string  
> }  
> numberOfProducts: {  
> type: long  
> }  
> }  
> \_parent: {  
> type: store  
> }  
> }  
> }
> 
> Following is the bulk input file:
> 
> { "index" : { "\_index" : "parent\_child", "\_type" : "store", "\_id" :  
> "store1" } }  
> { "name" : "auchan", "owner" : "chris" }  
> { "index" : { "\_index" : "parent\_child", "\_type" : "department", "\_id" :  
> "department1", "parent" : "store1" } }  
> { "name" : "toys", "numberOfProducts" : 150 }  
> { "update" : { "\_index" : "parent\_child", "\_type" : "department", "\_id" :  
> "department2", "parent" : "store1" } }  
> {"doc" : { "name" : "dolls", "numberOfProducts" : 300 }, "doc\_as\_upsert"  
> : "true"}
> 
> Query -
> 
> {  
> "query": {  
> "has\_parent": {  
> "type": "store",  
> "query": {  
> "match\_all": {}  
> }  
> }  
> }  
> }

--  
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: ![Poorva\_Potnis](https://avatars.discourse-cdn.com/v4/letter/p/e68b1a/32.png) [@Poorva\_Potnis](https://discuss.elastic.co/u/Poorva_Potnis)
#### Post date: [August 5, 2013, 5:38pm UTC](https://discuss.elastic.co/t/using-parent-property-in-update-api-doesnt-seem-to-work/13058/3 "2013-08-05T17:38:34Z")

</div>

Thanks! I opened the issue as you suggested.  
Poorva

On Monday, August 5, 2013 7:34:59 AM UTC-7, Luca Cavanna wrote:

> Hi Poorva,  
> you are right, I looked into it and this is most likely a bug. It seems  
> that we do read the parent, but we only use it for routing when updating a  
> document, while in case of doc\_as\_upsert we should also add the \_parent to  
> the documents. Would you mind opening an issue here[https://github.com/elasticsearch/elasticsearch/issues](https://github.com/elasticsearch/elasticsearch/issues)  
> ?
> 
> On Sunday, August 4, 2013 2:08:33 AM UTC+2, Poorva Potnis wrote:
> 
> > Hi -
> > 
> > If I try to add a document using the bulk update API (doc\_as\_upsert=true)  
> > and set its parent property, I do not see the document as the child of the  
> > specified parent when I make a has\_parent query. Can you please help see  
> > what could be wrong with the below. Thanks in advance.
> > 
> > Following is the mapping:
> > 
> > mappings: {  
> > store: {  
> > properties: {  
> > name: {  
> > type: string  
> > }  
> > owner: {  
> > type: string  
> > }  
> > }  
> > }  
> > department: {  
> > \_routing: {  
> > required: true  
> > }  
> > properties: {  
> > name: {  
> > type: string  
> > }  
> > numberOfProducts: {  
> > type: long  
> > }  
> > }  
> > \_parent: {  
> > type: store  
> > }  
> > }  
> > }
> > 
> > Following is the bulk input file:
> > 
> > { "index" : { "\_index" : "parent\_child", "\_type" : "store", "\_id" :  
> > "store1" } }  
> > { "name" : "auchan", "owner" : "chris" }  
> > { "index" : { "\_index" : "parent\_child", "\_type" : "department", "\_id" :  
> > "department1", "parent" : "store1" } }  
> > { "name" : "toys", "numberOfProducts" : 150 }  
> > { "update" : { "\_index" : "parent\_child", "\_type" : "department", "\_id" :  
> > "department2", "parent" : "store1" } }  
> > {"doc" : { "name" : "dolls", "numberOfProducts" : 300 }, "doc\_as\_upsert"  
> > : "true"}
> > 
> > Query -
> > 
> > {  
> > "query": {  
> > "has\_parent": {  
> > "type": "store",  
> > "query": {  
> > "match\_all": {}  
> > }  
> > }  
> > }  
> > }

--  
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: ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)
#### Post date: [August 7, 2013, 8:03am UTC](https://discuss.elastic.co/t/using-parent-property-in-update-api-doesnt-seem-to-work/13058/4 "2013-08-07T08:03:35Z")

</div>

Thanks a lot for opening the issue, it's fixed now. Also, the fix has  
already been released with 0.90.3.

Cheers  
Luca

On Monday, August 5, 2013 7:38:34 PM UTC+2, Poorva Potnis wrote:

> Thanks! I opened the issue as you suggested.  
> Poorva
> 
> On Monday, August 5, 2013 7:34:59 AM UTC-7, Luca Cavanna wrote:
> 
> > Hi Poorva,  
> > you are right, I looked into it and this is most likely a bug. It seems  
> > that we do read the parent, but we only use it for routing when updating a  
> > document, while in case of doc\_as\_upsert we should also add the \_parent to  
> > the documents. Would you mind opening an issue here[https://github.com/elasticsearch/elasticsearch/issues](https://github.com/elasticsearch/elasticsearch/issues)  
> > ?
> > 
> > On Sunday, August 4, 2013 2:08:33 AM UTC+2, Poorva Potnis wrote:
> > 
> > > Hi -
> > > 
> > > If I try to add a document using the bulk update API  
> > > (doc\_as\_upsert=true) and set its parent property, I do not see the document  
> > > as the child of the specified parent when I make a has\_parent query. Can  
> > > you please help see what could be wrong with the below. Thanks in advance.
> > > 
> > > Following is the mapping:
> > > 
> > > mappings: {  
> > > store: {  
> > > properties: {  
> > > name: {  
> > > type: string  
> > > }  
> > > owner: {  
> > > type: string  
> > > }  
> > > }  
> > > }  
> > > department: {  
> > > \_routing: {  
> > > required: true  
> > > }  
> > > properties: {  
> > > name: {  
> > > type: string  
> > > }  
> > > numberOfProducts: {  
> > > type: long  
> > > }  
> > > }  
> > > \_parent: {  
> > > type: store  
> > > }  
> > > }  
> > > }
> > > 
> > > Following is the bulk input file:
> > > 
> > > { "index" : { "\_index" : "parent\_child", "\_type" : "store", "\_id" :  
> > > "store1" } }  
> > > { "name" : "auchan", "owner" : "chris" }  
> > > { "index" : { "\_index" : "parent\_child", "\_type" : "department", "\_id" :  
> > > "department1", "parent" : "store1" } }  
> > > { "name" : "toys", "numberOfProducts" : 150 }  
> > > { "update" : { "\_index" : "parent\_child", "\_type" : "department", "\_id"  
> > > : "department2", "parent" : "store1" } }  
> > > {"doc" : { "name" : "dolls", "numberOfProducts" : 300 },  
> > > "doc\_as\_upsert" : "true"}
> > > 
> > > Query -
> > > 
> > > {  
> > > "query": {  
> > > "has\_parent": {  
> > > "type": "store",  
> > > "query": {  
> > > "match\_all": {}  
> > > }  
> > > }  
> > > }  
> > > }

--  
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:22am UTC](https://discuss.elastic.co/t/using-parent-property-in-update-api-doesnt-seem-to-work/13058/5 "2017-07-06T02:22:29Z")

</div>


