# Can't GET document with parent; also can I retrieve its \_parent ID?

**URL:** <https://discuss.elastic.co/t/cant-get-document-with-parent-also-can-i-retrieve-its--parent-id/5495>\
**Category:** Elasticsearch\
**Created:** [October 1, 2011, 4:46pm UTC](https://discuss.elastic.co/t/cant-get-document-with-parent-also-can-i-retrieve-its--parent-id/5495 "2011-10-01T16:46:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_A\_Brown](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matthew_a_brown/32/2699_2.png) [@Matthew\_A\_Brown](https://discuss.elastic.co/u/Matthew_A_Brown)\
**Post date:** [October 1, 2011, 4:46pm UTC](https://discuss.elastic.co/t/cant-get-document-with-parent-also-can-i-retrieve-its--parent-id/5495/1 "2011-10-01T16:46:32Z")

</div>

Hi there,

Seeing two pieces of unexpected behavior here:

$ curl -s -XDELETE [http://localhost:9200/?pretty=true](http://localhost:9200/?pretty=true)  
{  
"ok" : true,  
"acknowledged" : true  
}  
$ curl -s -XPOST [http://localhost:9200/test?pretty=true](http://localhost:9200/test?pretty=true)  
{  
"ok" : true,  
"acknowledged" : true  
}  
$ curl -s -XPUT [http://localhost:9200/test/post/\_mapping?pretty=true](http://localhost:9200/test/post/_mapping?pretty=true) -  
d '{"post":{"properties":{"title":{"type":"string"}}}}'  
{  
"ok" : true,  
"acknowledged" : true  
}  
$ curl -s -XPUT [http://localhost:9200/test/comment/\_mapping?pretty=true](http://localhost:9200/test/comment/_mapping?pretty=true)  
-d '{"comment":{"\_parent":{"type":"post"},"properties":{"content":  
{"type":"string"}}}}'  
{  
"ok" : true,  
"acknowledged" : true  
}  
$ curl -s -XPUT [http://localhost:9200/test/post/1](http://localhost:9200/test/post/1) -d '{"title":"Test  
Post"}'  
{"ok":true,"\_index":"test","\_type":"post","\_id":"1","\_version":1}  
$ curl -s -XPUT '[http://localhost:9200/test/comment/2](http://localhost:9200/test/comment/2)?  
parent=1&pretty=true&refresh=true' -d '{"content":"Test Comment"}'  
{  
"ok" : true,  
"\_index" : "test",  
"\_type" : "comment",  
"\_id" : "2",  
"\_version" : 1  
}  
$ curl -s [http://localhost:9200/test/comment/2?pretty=true](http://localhost:9200/test/comment/2?pretty=true)  
{  
"\_index" : "test",  
"\_type" : "comment",  
"\_id" : "2",  
"exists" : false  
}  
$ curl -s [http://localhost:9200/test/comment/\_search?pretty=true](http://localhost:9200/test/comment/_search?pretty=true)  
{  
"took" : 3,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "test",  
"\_type" : "comment",  
"\_id" : "2",  
"\_score" : 1.0, "\_source" : {"content":"Test Comment"}  
} ]  
}  
}

1. It seems that I can't look up the document at all when I index it  
with a parent param.
2. I note that the search result doesn't contain a reference to the  
parent. Is there a way to access the parent when retrieving the doc?

Am I doing something wrong?

Thanks!  
Mat

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [October 2, 2011, 1:14pm UTC](https://discuss.elastic.co/t/cant-get-document-with-parent-also-can-i-retrieve-its--parent-id/5495/2 "2011-10-02T13:14:18Z")

</div>

1. Because the parent parameter controls the routing, you need to provide  
the parent value in the routing parameter when you do a GET for the child  
document.

2. Ask for \_parent in the fields when you search / GET the doc. As for both  
\_source and \_parent if you want both.

On Sat, Oct 1, 2011 at 7:46 PM, Mat Brown [mat.a.brown@gmail.com](mailto:mat.a.brown@gmail.com) wrote:

> Hi there,
> 
> Seeing two pieces of unexpected behavior here:
> 
> $ curl -s -XDELETE [http://localhost:9200/?pretty=true](http://localhost:9200/?pretty=true)  
> {  
> "ok" : true,  
> "acknowledged" : true  
> }  
> $ curl -s -XPOST [http://localhost:9200/test?pretty=true](http://localhost:9200/test?pretty=true)  
> {  
> "ok" : true,  
> "acknowledged" : true  
> }  
> $ curl -s -XPUT [http://localhost:9200/test/post/\_mapping?pretty=true](http://localhost:9200/test/post/_mapping?pretty=true) -  
> d '{"post":{"properties":{"title":{"type":"string"}}}}'  
> {  
> "ok" : true,  
> "acknowledged" : true  
> }  
> $ curl -s -XPUT [http://localhost:9200/test/comment/\_mapping?pretty=true](http://localhost:9200/test/comment/_mapping?pretty=true)  
> -d '{"comment":{"\_parent":{"type":"post"},"properties":{"content":  
> {"type":"string"}}}}'  
> {  
> "ok" : true,  
> "acknowledged" : true  
> }  
> $ curl -s -XPUT [http://localhost:9200/test/post/1](http://localhost:9200/test/post/1) -d '{"title":"Test  
> Post"}'  
> {"ok":true,"\_index":"test","\_type":"post","\_id":"1","\_version":1}  
> $ curl -s -XPUT '[http://localhost:9200/test/comment/2](http://localhost:9200/test/comment/2)?  
> parent=1&pretty=true&refresh=true' -d '{"content":"Test Comment"}'  
> {  
> "ok" : true,  
> "\_index" : "test",  
> "\_type" : "comment",  
> "\_id" : "2",  
> "\_version" : 1  
> }  
> $ curl -s [http://localhost:9200/test/comment/2?pretty=true](http://localhost:9200/test/comment/2?pretty=true)  
> {  
> "\_index" : "test",  
> "\_type" : "comment",  
> "\_id" : "2",  
> "exists" : false  
> }  
> $ curl -s [http://localhost:9200/test/comment/\_search?pretty=true](http://localhost:9200/test/comment/_search?pretty=true)  
> {  
> "took" : 3,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 1,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "test",  
> "\_type" : "comment",  
> "\_id" : "2",  
> "\_score" : 1.0, "\_source" : {"content":"Test Comment"}  
> } ]  
> }  
> }
> 
> 1. It seems that I can't look up the document at all when I index it  
> with a parent param.
> 2. I note that the search result doesn't contain a reference to the  
> parent. Is there a way to access the parent when retrieving the doc?
> 
> Am I doing something wrong?
> 
> Thanks!  
> Mat

---

<div class="post-metadata">

**Author:** ![Matthew\_A\_Brown](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matthew_a_brown/32/2699_2.png) [@Matthew\_A\_Brown](https://discuss.elastic.co/u/Matthew_A_Brown)\
**Post date:** [October 2, 2011, 4:27pm UTC](https://discuss.elastic.co/t/cant-get-document-with-parent-also-can-i-retrieve-its--parent-id/5495/3 "2011-10-02T16:27:43Z")

</div>

Thank you!!!  
On Oct 2, 2011 6:14 AM, "Shay Banon" [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> 1. Because the parent parameter controls the routing, you need to provide  
> the parent value in the routing parameter when you do a GET for the child  
> document.
> 
> 2. Ask for \_parent in the fields when you search / GET the doc. As for  
> both  
> \_source and \_parent if you want both.
> 
> On Sat, Oct 1, 2011 at 7:46 PM, Mat Brown [mat.a.brown@gmail.com](mailto:mat.a.brown@gmail.com) wrote:
> 
> > Hi there,
> > 
> > Seeing two pieces of unexpected behavior here:
> > 
> > $ curl -s -XDELETE [http://localhost:9200/?pretty=true](http://localhost:9200/?pretty=true)  
> > {  
> > "ok" : true,  
> > "acknowledged" : true  
> > }  
> > $ curl -s -XPOST [http://localhost:9200/test?pretty=true](http://localhost:9200/test?pretty=true)  
> > {  
> > "ok" : true,  
> > "acknowledged" : true  
> > }  
> > $ curl -s -XPUT [http://localhost:9200/test/post/\_mapping?pretty=true](http://localhost:9200/test/post/_mapping?pretty=true) -  
> > d '{"post":{"properties":{"title":{"type":"string"}}}}'  
> > {  
> > "ok" : true,  
> > "acknowledged" : true  
> > }  
> > $ curl -s -XPUT [http://localhost:9200/test/comment/\_mapping?pretty=true](http://localhost:9200/test/comment/_mapping?pretty=true)  
> > -d '{"comment":{"\_parent":{"type":"post"},"properties":{"content":  
> > {"type":"string"}}}}'  
> > {  
> > "ok" : true,  
> > "acknowledged" : true  
> > }  
> > $ curl -s -XPUT [http://localhost:9200/test/post/1](http://localhost:9200/test/post/1) -d '{"title":"Test  
> > Post"}'  
> > {"ok":true,"\_index":"test","\_type":"post","\_id":"1","\_version":1}  
> > $ curl -s -XPUT '[http://localhost:9200/test/comment/2](http://localhost:9200/test/comment/2)?  
> > parent=1&pretty=true&refresh=true' -d '{"content":"Test Comment"}'  
> > {  
> > "ok" : true,  
> > "\_index" : "test",  
> > "\_type" : "comment",  
> > "\_id" : "2",  
> > "\_version" : 1  
> > }  
> > $ curl -s [http://localhost:9200/test/comment/2?pretty=true](http://localhost:9200/test/comment/2?pretty=true)  
> > {  
> > "\_index" : "test",  
> > "\_type" : "comment",  
> > "\_id" : "2",  
> > "exists" : false  
> > }  
> > $ curl -s [http://localhost:9200/test/comment/\_search?pretty=true](http://localhost:9200/test/comment/_search?pretty=true)  
> > {  
> > "took" : 3,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 1,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_index" : "test",  
> > "\_type" : "comment",  
> > "\_id" : "2",  
> > "\_score" : 1.0, "\_source" : {"content":"Test Comment"}  
> > } ]  
> > }  
> > }
> > 
> > 1. It seems that I can't look up the document at all when I index it  
> > with a parent param.
> > 2. I note that the search result doesn't contain a reference to the  
> > parent. Is there a way to access the parent when retrieving the doc?
> > 
> > Am I doing something wrong?
> > 
> > Thanks!  
> > Mat

---

<div class="post-metadata">

**Author:** ![Matthew\_A\_Brown](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matthew_a_brown/32/2699_2.png) [@Matthew\_A\_Brown](https://discuss.elastic.co/u/Matthew_A_Brown)\
**Post date:** [October 4, 2011, 4:22pm UTC](https://discuss.elastic.co/t/cant-get-document-with-parent-also-can-i-retrieve-its--parent-id/5495/4 "2011-10-04T16:22:27Z")

</div>

Hey Shay,

No such luck:

$ curl -s -XDELETE '[http://localhost:9200/?pretty=true](http://localhost:9200/?pretty=true)'  
{  
"ok" : true,  
"acknowledged" : true  
}  
$ curl -s -XPOST '[http://localhost:9200/test?pretty=true](http://localhost:9200/test?pretty=true)'  
{  
"ok" : true,  
"acknowledged" : true  
}  
$ curl -s -XPUT '[http://localhost:9200/test/post/\_mapping?pretty=true](http://localhost:9200/test/post/_mapping?pretty=true)'  
-d '{"post":{"properties":{"title":{"type":"string"}}}}'  
{  
"ok" : true,  
"acknowledged" : true  
}  
$ curl -s -XPUT  
'[http://localhost:9200/test/comment/\_mapping?pretty=true](http://localhost:9200/test/comment/_mapping?pretty=true)' -d  
'{"comment":{"\_parent":{"type":"post"},"properties":{"content":  
{"type":"string"}}}}'  
{  
"ok" : true,  
"acknowledged" : true  
}  
$ curl -s -XPUT [http://localhost:9200/test/post/1](http://localhost:9200/test/post/1) -d '{"title":"Test Post"}'  
{"ok":true,"\_index":"test","\_type":"post","\_id":"1","\_version":1}  
$ curl -s -XPUT  
'[http://localhost:9200/test/comment/2?parent=1&pretty=true&refresh=true](http://localhost:9200/test/comment/2?parent=1&pretty=true&refresh=true)'  
-d '{"content":"Test Comment"}'  
{  
"ok" : true,  
"\_index" : "test",  
"\_type" : "comment",  
"\_id" : "2",  
"\_version" : 1  
}  
$ curl -s '[http://localhost:9200/test/comment/2?parent=1&pretty=true](http://localhost:9200/test/comment/2?parent=1&pretty=true)'  
{  
"\_index" : "test",  
"\_type" : "comment",  
"\_id" : "2",  
"exists" : false  
}  
$ curl -s '[http://localhost:9200/test/comment/\_search?pretty=true](http://localhost:9200/test/comment/_search?pretty=true)'  
{  
"took" : 2,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "test",  
"\_type" : "comment",  
"\_id" : "2",  
"\_score" : 1.0, "\_source" : {"content":"Test Comment"}  
} ]  
}  
}

Anything else I might be doing wrong? Thanks!

Mat

On Sun, Oct 2, 2011 at 10:27, Matthew A. Brown [mat.a.brown@gmail.com](mailto:mat.a.brown@gmail.com) wrote:

> Thank you!!!
> 
> On Oct 2, 2011 6:14 AM, "Shay Banon" [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> 
> > 1. Because the parent parameter controls the routing, you need to provide  
> > the parent value in the routing parameter when you do a GET for the child  
> > document.
> > 
> > 2. Ask for \_parent in the fields when you search / GET the doc. As for  
> > both  
> > \_source and \_parent if you want both.
> > 
> > On Sat, Oct 1, 2011 at 7:46 PM, Mat Brown [mat.a.brown@gmail.com](mailto:mat.a.brown@gmail.com) wrote:
> > 
> > > Hi there,
> > > 
> > > Seeing two pieces of unexpected behavior here:
> > > 
> > > $ curl -s -XDELETE [http://localhost:9200/?pretty=true](http://localhost:9200/?pretty=true)  
> > > {  
> > > "ok" : true,  
> > > "acknowledged" : true  
> > > }  
> > > $ curl -s -XPOST [http://localhost:9200/test?pretty=true](http://localhost:9200/test?pretty=true)  
> > > {  
> > > "ok" : true,  
> > > "acknowledged" : true  
> > > }  
> > > $ curl -s -XPUT [http://localhost:9200/test/post/\_mapping?pretty=true](http://localhost:9200/test/post/_mapping?pretty=true) -  
> > > d '{"post":{"properties":{"title":{"type":"string"}}}}'  
> > > {  
> > > "ok" : true,  
> > > "acknowledged" : true  
> > > }  
> > > $ curl -s -XPUT [http://localhost:9200/test/comment/\_mapping?pretty=true](http://localhost:9200/test/comment/_mapping?pretty=true)  
> > > -d '{"comment":{"\_parent":{"type":"post"},"properties":{"content":  
> > > {"type":"string"}}}}'  
> > > {  
> > > "ok" : true,  
> > > "acknowledged" : true  
> > > }  
> > > $ curl -s -XPUT [http://localhost:9200/test/post/1](http://localhost:9200/test/post/1) -d '{"title":"Test  
> > > Post"}'  
> > > {"ok":true,"\_index":"test","\_type":"post","\_id":"1","\_version":1}  
> > > $ curl -s -XPUT '[http://localhost:9200/test/comment/2](http://localhost:9200/test/comment/2)?  
> > > parent=1&pretty=true&refresh=true' -d '{"content":"Test Comment"}'  
> > > {  
> > > "ok" : true,  
> > > "\_index" : "test",  
> > > "\_type" : "comment",  
> > > "\_id" : "2",  
> > > "\_version" : 1  
> > > }  
> > > $ curl -s [http://localhost:9200/test/comment/2?pretty=true](http://localhost:9200/test/comment/2?pretty=true)  
> > > {  
> > > "\_index" : "test",  
> > > "\_type" : "comment",  
> > > "\_id" : "2",  
> > > "exists" : false  
> > > }  
> > > $ curl -s [http://localhost:9200/test/comment/\_search?pretty=true](http://localhost:9200/test/comment/_search?pretty=true)  
> > > {  
> > > "took" : 3,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 5,  
> > > "successful" : 5,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 1,  
> > > "max\_score" : 1.0,  
> > > "hits" : [ {  
> > > "\_index" : "test",  
> > > "\_type" : "comment",  
> > > "\_id" : "2",  
> > > "\_score" : 1.0, "\_source" : {"content":"Test Comment"}  
> > > } ]  
> > > }  
> > > }
> > > 
> > > 1. It seems that I can't look up the document at all when I index it  
> > > with a parent param.
> > > 2. I note that the search result doesn't contain a reference to the  
> > > parent. Is there a way to access the parent when retrieving the doc?
> > > 
> > > Am I doing something wrong?
> > > 
> > > Thanks!  
> > > Mat

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [October 4, 2011, 4:48pm UTC](https://discuss.elastic.co/t/cant-get-document-with-parent-also-can-i-retrieve-its--parent-id/5495/5 "2011-10-04T16:48:32Z")

</div>

From briefly looking at it (on the go...), you should pass routing=1 for the  
get request, there is no handle for parent (which effectively is the  
routing).

On Tue, Oct 4, 2011 at 6:22 PM, Matthew A. Brown [mat.a.brown@gmail.com](mailto:mat.a.brown@gmail.com)wrote:

> Hey Shay,
> 
> No such luck:
> 
> $ curl -s -XDELETE '[http://localhost:9200/?pretty=true](http://localhost:9200/?pretty=true)'  
> {  
> "ok" : true,  
> "acknowledged" : true  
> }  
> $ curl -s -XPOST '[http://localhost:9200/test?pretty=true](http://localhost:9200/test?pretty=true)'  
> {  
> "ok" : true,  
> "acknowledged" : true  
> }  
> $ curl -s -XPUT '[http://localhost:9200/test/post/\_mapping?pretty=true](http://localhost:9200/test/post/_mapping?pretty=true)'  
> -d '{"post":{"properties":{"title":{"type":"string"}}}}'  
> {  
> "ok" : true,  
> "acknowledged" : true  
> }  
> $ curl -s -XPUT  
> '[http://localhost:9200/test/comment/\_mapping?pretty=true](http://localhost:9200/test/comment/_mapping?pretty=true)' -d  
> '{"comment":{"\_parent":{"type":"post"},"properties":{"content":  
> {"type":"string"}}}}'  
> {  
> "ok" : true,  
> "acknowledged" : true  
> }  
> $ curl -s -XPUT [http://localhost:9200/test/post/1](http://localhost:9200/test/post/1) -d '{"title":"Test  
> Post"}'  
> {"ok":true,"\_index":"test","\_type":"post","\_id":"1","\_version":1}  
> $ curl -s -XPUT  
> '[http://localhost:9200/test/comment/2?parent=1&pretty=true&refresh=true](http://localhost:9200/test/comment/2?parent=1&pretty=true&refresh=true)'  
> -d '{"content":"Test Comment"}'  
> {  
> "ok" : true,  
> "\_index" : "test",  
> "\_type" : "comment",  
> "\_id" : "2",  
> "\_version" : 1  
> }  
> $ curl -s '[http://localhost:9200/test/comment/2?parent=1&pretty=true](http://localhost:9200/test/comment/2?parent=1&pretty=true)'  
> {  
> "\_index" : "test",  
> "\_type" : "comment",  
> "\_id" : "2",  
> "exists" : false  
> }  
> $ curl -s '[http://localhost:9200/test/comment/\_search?pretty=true](http://localhost:9200/test/comment/_search?pretty=true)'  
> {  
> "took" : 2,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 1,  
> "max\_score" : 1.0,  
> "hits" : [ {  
> "\_index" : "test",  
> "\_type" : "comment",  
> "\_id" : "2",  
> "\_score" : 1.0, "\_source" : {"content":"Test Comment"}  
> } ]  
> }  
> }
> 
> Anything else I might be doing wrong? Thanks!
> 
> Mat
> 
> On Sun, Oct 2, 2011 at 10:27, Matthew A. Brown [mat.a.brown@gmail.com](mailto:mat.a.brown@gmail.com)  
> wrote:
> 
> > Thank you!!!
> > 
> > On Oct 2, 2011 6:14 AM, "Shay Banon" [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> > 
> > > 1. Because the parent parameter controls the routing, you need to  
> > > provide  
> > > the parent value in the routing parameter when you do a GET for the  
> > > child  
> > > document.
> > > 
> > > 2. Ask for \_parent in the fields when you search / GET the doc. As for  
> > > both  
> > > \_source and \_parent if you want both.
> > > 
> > > On Sat, Oct 1, 2011 at 7:46 PM, Mat Brown [mat.a.brown@gmail.com](mailto:mat.a.brown@gmail.com)  
> > > wrote:
> > > 
> > > > Hi there,
> > > > 
> > > > Seeing two pieces of unexpected behavior here:
> > > > 
> > > > $ curl -s -XDELETE [http://localhost:9200/?pretty=true](http://localhost:9200/?pretty=true)  
> > > > {  
> > > > "ok" : true,  
> > > > "acknowledged" : true  
> > > > }  
> > > > $ curl -s -XPOST [http://localhost:9200/test?pretty=true](http://localhost:9200/test?pretty=true)  
> > > > {  
> > > > "ok" : true,  
> > > > "acknowledged" : true  
> > > > }  
> > > > $ curl -s -XPUT [http://localhost:9200/test/post/\_mapping?pretty=true](http://localhost:9200/test/post/_mapping?pretty=true) -  
> > > > d '{"post":{"properties":{"title":{"type":"string"}}}}'  
> > > > {  
> > > > "ok" : true,  
> > > > "acknowledged" : true  
> > > > }  
> > > > $ curl -s -XPUT  
> > > > [http://localhost:9200/test/comment/\_mapping?pretty=true](http://localhost:9200/test/comment/_mapping?pretty=true)  
> > > > -d '{"comment":{"\_parent":{"type":"post"},"properties":{"content":  
> > > > {"type":"string"}}}}'  
> > > > {  
> > > > "ok" : true,  
> > > > "acknowledged" : true  
> > > > }  
> > > > $ curl -s -XPUT [http://localhost:9200/test/post/1](http://localhost:9200/test/post/1) -d '{"title":"Test  
> > > > Post"}'  
> > > > {"ok":true,"\_index":"test","\_type":"post","\_id":"1","\_version":1}  
> > > > $ curl -s -XPUT '[http://localhost:9200/test/comment/2](http://localhost:9200/test/comment/2)?  
> > > > parent=1&pretty=true&refresh=true' -d '{"content":"Test Comment"}'  
> > > > {  
> > > > "ok" : true,  
> > > > "\_index" : "test",  
> > > > "\_type" : "comment",  
> > > > "\_id" : "2",  
> > > > "\_version" : 1  
> > > > }  
> > > > $ curl -s [http://localhost:9200/test/comment/2?pretty=true](http://localhost:9200/test/comment/2?pretty=true)  
> > > > {  
> > > > "\_index" : "test",  
> > > > "\_type" : "comment",  
> > > > "\_id" : "2",  
> > > > "exists" : false  
> > > > }  
> > > > $ curl -s [http://localhost:9200/test/comment/\_search?pretty=true](http://localhost:9200/test/comment/_search?pretty=true)  
> > > > {  
> > > > "took" : 3,  
> > > > "timed\_out" : false,  
> > > > "\_shards" : {  
> > > > "total" : 5,  
> > > > "successful" : 5,  
> > > > "failed" : 0  
> > > > },  
> > > > "hits" : {  
> > > > "total" : 1,  
> > > > "max\_score" : 1.0,  
> > > > "hits" : [ {  
> > > > "\_index" : "test",  
> > > > "\_type" : "comment",  
> > > > "\_id" : "2",  
> > > > "\_score" : 1.0, "\_source" : {"content":"Test Comment"}  
> > > > } ]  
> > > > }  
> > > > }
> > > > 
> > > > 1. It seems that I can't look up the document at all when I index it  
> > > > with a parent param.
> > > > 2. I note that the search result doesn't contain a reference to the  
> > > > parent. Is there a way to access the parent when retrieving the doc?
> > > > 
> > > > Am I doing something wrong?
> > > > 
> > > > Thanks!  
> > > > Mat

---

<div class="post-metadata">

**Author:** ![Matthew\_A\_Brown](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matthew_a_brown/32/2699_2.png) [@Matthew\_A\_Brown](https://discuss.elastic.co/u/Matthew_A_Brown)\
**Post date:** [October 4, 2011, 4:54pm UTC](https://discuss.elastic.co/t/cant-get-document-with-parent-also-can-i-retrieve-its--parent-id/5495/6 "2011-10-04T16:54:52Z")

</div>

Ah, got it. Thank you! So the `routing` param should just always be  
the parent ID?

On Tue, Oct 4, 2011 at 10:48, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> From briefly looking at it (on the go...), you should pass routing=1 for the  
> get request, there is no handle for parent (which effectively is the  
> routing).
> 
> On Tue, Oct 4, 2011 at 6:22 PM, Matthew A. Brown [mat.a.brown@gmail.com](mailto:mat.a.brown@gmail.com)  
> wrote:
> 
> > Hey Shay,
> > 
> > No such luck:
> > 
> > $ curl -s -XDELETE '[http://localhost:9200/?pretty=true](http://localhost:9200/?pretty=true)'  
> > {  
> > "ok" : true,  
> > "acknowledged" : true  
> > }  
> > $ curl -s -XPOST '[http://localhost:9200/test?pretty=true](http://localhost:9200/test?pretty=true)'  
> > {  
> > "ok" : true,  
> > "acknowledged" : true  
> > }  
> > $ curl -s -XPUT '[http://localhost:9200/test/post/\_mapping?pretty=true](http://localhost:9200/test/post/_mapping?pretty=true)'  
> > -d '{"post":{"properties":{"title":{"type":"string"}}}}'  
> > {  
> > "ok" : true,  
> > "acknowledged" : true  
> > }  
> > $ curl -s -XPUT  
> > '[http://localhost:9200/test/comment/\_mapping?pretty=true](http://localhost:9200/test/comment/_mapping?pretty=true)' -d  
> > '{"comment":{"\_parent":{"type":"post"},"properties":{"content":  
> > {"type":"string"}}}}'  
> > {  
> > "ok" : true,  
> > "acknowledged" : true  
> > }  
> > $ curl -s -XPUT [http://localhost:9200/test/post/1](http://localhost:9200/test/post/1) -d '{"title":"Test  
> > Post"}'  
> > {"ok":true,"\_index":"test","\_type":"post","\_id":"1","\_version":1}  
> > $ curl -s -XPUT  
> > '[http://localhost:9200/test/comment/2?parent=1&pretty=true&refresh=true](http://localhost:9200/test/comment/2?parent=1&pretty=true&refresh=true)'  
> > -d '{"content":"Test Comment"}'  
> > {  
> > "ok" : true,  
> > "\_index" : "test",  
> > "\_type" : "comment",  
> > "\_id" : "2",  
> > "\_version" : 1  
> > }  
> > $ curl -s '[http://localhost:9200/test/comment/2?parent=1&pretty=true](http://localhost:9200/test/comment/2?parent=1&pretty=true)'  
> > {  
> > "\_index" : "test",  
> > "\_type" : "comment",  
> > "\_id" : "2",  
> > "exists" : false  
> > }  
> > $ curl -s '[http://localhost:9200/test/comment/\_search?pretty=true](http://localhost:9200/test/comment/_search?pretty=true)'  
> > {  
> > "took" : 2,  
> > "timed\_out" : false,  
> > "\_shards" : {  
> > "total" : 5,  
> > "successful" : 5,  
> > "failed" : 0  
> > },  
> > "hits" : {  
> > "total" : 1,  
> > "max\_score" : 1.0,  
> > "hits" : [ {  
> > "\_index" : "test",  
> > "\_type" : "comment",  
> > "\_id" : "2",  
> > "\_score" : 1.0, "\_source" : {"content":"Test Comment"}  
> > } ]  
> > }  
> > }
> > 
> > Anything else I might be doing wrong? Thanks!
> > 
> > Mat
> > 
> > On Sun, Oct 2, 2011 at 10:27, Matthew A. Brown [mat.a.brown@gmail.com](mailto:mat.a.brown@gmail.com)  
> > wrote:
> > 
> > > Thank you!!!
> > > 
> > > On Oct 2, 2011 6:14 AM, "Shay Banon" [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> > > 
> > > > 1. Because the parent parameter controls the routing, you need to  
> > > > provide  
> > > > the parent value in the routing parameter when you do a GET for the  
> > > > child  
> > > > document.
> > > > 
> > > > 2. Ask for \_parent in the fields when you search / GET the doc. As for  
> > > > both  
> > > > \_source and \_parent if you want both.
> > > > 
> > > > On Sat, Oct 1, 2011 at 7:46 PM, Mat Brown [mat.a.brown@gmail.com](mailto:mat.a.brown@gmail.com)  
> > > > wrote:
> > > > 
> > > > > Hi there,
> > > > > 
> > > > > Seeing two pieces of unexpected behavior here:
> > > > > 
> > > > > $ curl -s -XDELETE [http://localhost:9200/?pretty=true](http://localhost:9200/?pretty=true)  
> > > > > {  
> > > > > "ok" : true,  
> > > > > "acknowledged" : true  
> > > > > }  
> > > > > $ curl -s -XPOST [http://localhost:9200/test?pretty=true](http://localhost:9200/test?pretty=true)  
> > > > > {  
> > > > > "ok" : true,  
> > > > > "acknowledged" : true  
> > > > > }  
> > > > > $ curl -s -XPUT [http://localhost:9200/test/post/\_mapping?pretty=true](http://localhost:9200/test/post/_mapping?pretty=true) -  
> > > > > d '{"post":{"properties":{"title":{"type":"string"}}}}'  
> > > > > {  
> > > > > "ok" : true,  
> > > > > "acknowledged" : true  
> > > > > }  
> > > > > $ curl -s -XPUT  
> > > > > [http://localhost:9200/test/comment/\_mapping?pretty=true](http://localhost:9200/test/comment/_mapping?pretty=true)  
> > > > > -d '{"comment":{"\_parent":{"type":"post"},"properties":{"content":  
> > > > > {"type":"string"}}}}'  
> > > > > {  
> > > > > "ok" : true,  
> > > > > "acknowledged" : true  
> > > > > }  
> > > > > $ curl -s -XPUT [http://localhost:9200/test/post/1](http://localhost:9200/test/post/1) -d '{"title":"Test  
> > > > > Post"}'  
> > > > > {"ok":true,"\_index":"test","\_type":"post","\_id":"1","\_version":1}  
> > > > > $ curl -s -XPUT '[http://localhost:9200/test/comment/2](http://localhost:9200/test/comment/2)?  
> > > > > parent=1&pretty=true&refresh=true' -d '{"content":"Test Comment"}'  
> > > > > {  
> > > > > "ok" : true,  
> > > > > "\_index" : "test",  
> > > > > "\_type" : "comment",  
> > > > > "\_id" : "2",  
> > > > > "\_version" : 1  
> > > > > }  
> > > > > $ curl -s [http://localhost:9200/test/comment/2?pretty=true](http://localhost:9200/test/comment/2?pretty=true)  
> > > > > {  
> > > > > "\_index" : "test",  
> > > > > "\_type" : "comment",  
> > > > > "\_id" : "2",  
> > > > > "exists" : false  
> > > > > }  
> > > > > $ curl -s [http://localhost:9200/test/comment/\_search?pretty=true](http://localhost:9200/test/comment/_search?pretty=true)  
> > > > > {  
> > > > > "took" : 3,  
> > > > > "timed\_out" : false,  
> > > > > "\_shards" : {  
> > > > > "total" : 5,  
> > > > > "successful" : 5,  
> > > > > "failed" : 0  
> > > > > },  
> > > > > "hits" : {  
> > > > > "total" : 1,  
> > > > > "max\_score" : 1.0,  
> > > > > "hits" : [ {  
> > > > > "\_index" : "test",  
> > > > > "\_type" : "comment",  
> > > > > "\_id" : "2",  
> > > > > "\_score" : 1.0, "\_source" : {"content":"Test Comment"}  
> > > > > } ]  
> > > > > }  
> > > > > }
> > > > > 
> > > > > 1. It seems that I can't look up the document at all when I index it  
> > > > > with a parent param.
> > > > > 2. I note that the search result doesn't contain a reference to the  
> > > > > parent. Is there a way to access the parent when retrieving the doc?
> > > > > 
> > > > > Am I doing something wrong?
> > > > > 
> > > > > Thanks!  
> > > > > Mat

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [October 4, 2011, 10:40pm UTC](https://discuss.elastic.co/t/cant-get-document-with-parent-also-can-i-retrieve-its--parent-id/5495/7 "2011-10-04T22:40:50Z")

</div>

Yes, this is effectively what happens when you set the parent value when  
indexing.

On Tue, Oct 4, 2011 at 6:54 PM, Matthew A. Brown [mat.a.brown@gmail.com](mailto:mat.a.brown@gmail.com)wrote:

> Ah, got it. Thank you! So the `routing` param should just always be  
> the parent ID?
> 
> On Tue, Oct 4, 2011 at 10:48, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> 
> > From briefly looking at it (on the go...), you should pass routing=1 for  
> > the  
> > get request, there is no handle for parent (which effectively is the  
> > routing).
> > 
> > On Tue, Oct 4, 2011 at 6:22 PM, Matthew A. Brown [mat.a.brown@gmail.com](mailto:mat.a.brown@gmail.com)  
> > wrote:
> > 
> > > Hey Shay,
> > > 
> > > No such luck:
> > > 
> > > $ curl -s -XDELETE '[http://localhost:9200/?pretty=true](http://localhost:9200/?pretty=true)'  
> > > {  
> > > "ok" : true,  
> > > "acknowledged" : true  
> > > }  
> > > $ curl -s -XPOST '[http://localhost:9200/test?pretty=true](http://localhost:9200/test?pretty=true)'  
> > > {  
> > > "ok" : true,  
> > > "acknowledged" : true  
> > > }  
> > > $ curl -s -XPUT '[http://localhost:9200/test/post/\_mapping?pretty=true](http://localhost:9200/test/post/_mapping?pretty=true)'  
> > > -d '{"post":{"properties":{"title":{"type":"string"}}}}'  
> > > {  
> > > "ok" : true,  
> > > "acknowledged" : true  
> > > }  
> > > $ curl -s -XPUT  
> > > '[http://localhost:9200/test/comment/\_mapping?pretty=true](http://localhost:9200/test/comment/_mapping?pretty=true)' -d  
> > > '{"comment":{"\_parent":{"type":"post"},"properties":{"content":  
> > > {"type":"string"}}}}'  
> > > {  
> > > "ok" : true,  
> > > "acknowledged" : true  
> > > }  
> > > $ curl -s -XPUT [http://localhost:9200/test/post/1](http://localhost:9200/test/post/1) -d '{"title":"Test  
> > > Post"}'  
> > > {"ok":true,"\_index":"test","\_type":"post","\_id":"1","\_version":1}  
> > > $ curl -s -XPUT  
> > > '[http://localhost:9200/test/comment/2?parent=1&pretty=true&refresh=true](http://localhost:9200/test/comment/2?parent=1&pretty=true&refresh=true)  
> > > '  
> > > -d '{"content":"Test Comment"}'  
> > > {  
> > > "ok" : true,  
> > > "\_index" : "test",  
> > > "\_type" : "comment",  
> > > "\_id" : "2",  
> > > "\_version" : 1  
> > > }  
> > > $ curl -s '[http://localhost:9200/test/comment/2?parent=1&pretty=true](http://localhost:9200/test/comment/2?parent=1&pretty=true)'  
> > > {  
> > > "\_index" : "test",  
> > > "\_type" : "comment",  
> > > "\_id" : "2",  
> > > "exists" : false  
> > > }  
> > > $ curl -s '[http://localhost:9200/test/comment/\_search?pretty=true](http://localhost:9200/test/comment/_search?pretty=true)'  
> > > {  
> > > "took" : 2,  
> > > "timed\_out" : false,  
> > > "\_shards" : {  
> > > "total" : 5,  
> > > "successful" : 5,  
> > > "failed" : 0  
> > > },  
> > > "hits" : {  
> > > "total" : 1,  
> > > "max\_score" : 1.0,  
> > > "hits" : [ {  
> > > "\_index" : "test",  
> > > "\_type" : "comment",  
> > > "\_id" : "2",  
> > > "\_score" : 1.0, "\_source" : {"content":"Test Comment"}  
> > > } ]  
> > > }  
> > > }
> > > 
> > > Anything else I might be doing wrong? Thanks!
> > > 
> > > Mat
> > > 
> > > On Sun, Oct 2, 2011 at 10:27, Matthew A. Brown [mat.a.brown@gmail.com](mailto:mat.a.brown@gmail.com)  
> > > wrote:
> > > 
> > > > Thank you!!!
> > > > 
> > > > On Oct 2, 2011 6:14 AM, "Shay Banon" [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> > > > 
> > > > > 1. Because the parent parameter controls the routing, you need to  
> > > > > provide  
> > > > > the parent value in the routing parameter when you do a GET for the  
> > > > > child  
> > > > > document.
> > > > > 
> > > > > 2. Ask for \_parent in the fields when you search / GET the doc. As  
> > > > > for  
> > > > > both  
> > > > > \_source and \_parent if you want both.
> > > > > 
> > > > > On Sat, Oct 1, 2011 at 7:46 PM, Mat Brown [mat.a.brown@gmail.com](mailto:mat.a.brown@gmail.com)  
> > > > > wrote:
> > > > > 
> > > > > > Hi there,
> > > > > > 
> > > > > > Seeing two pieces of unexpected behavior here:
> > > > > > 
> > > > > > $ curl -s -XDELETE [http://localhost:9200/?pretty=true](http://localhost:9200/?pretty=true)  
> > > > > > {  
> > > > > > "ok" : true,  
> > > > > > "acknowledged" : true  
> > > > > > }  
> > > > > > $ curl -s -XPOST [http://localhost:9200/test?pretty=true](http://localhost:9200/test?pretty=true)  
> > > > > > {  
> > > > > > "ok" : true,  
> > > > > > "acknowledged" : true  
> > > > > > }  
> > > > > > $ curl -s -XPUT  
> > > > > > [http://localhost:9200/test/post/\_mapping?pretty=true](http://localhost:9200/test/post/_mapping?pretty=true) -  
> > > > > > d '{"post":{"properties":{"title":{"type":"string"}}}}'  
> > > > > > {  
> > > > > > "ok" : true,  
> > > > > > "acknowledged" : true  
> > > > > > }  
> > > > > > $ curl -s -XPUT  
> > > > > > [http://localhost:9200/test/comment/\_mapping?pretty=true](http://localhost:9200/test/comment/_mapping?pretty=true)  
> > > > > > -d '{"comment":{"\_parent":{"type":"post"},"properties":{"content":  
> > > > > > {"type":"string"}}}}'  
> > > > > > {  
> > > > > > "ok" : true,  
> > > > > > "acknowledged" : true  
> > > > > > }  
> > > > > > $ curl -s -XPUT [http://localhost:9200/test/post/1](http://localhost:9200/test/post/1) -d  
> > > > > > '{"title":"Test  
> > > > > > Post"}'  
> > > > > > {"ok":true,"\_index":"test","\_type":"post","\_id":"1","\_version":1}  
> > > > > > $ curl -s -XPUT '[http://localhost:9200/test/comment/2](http://localhost:9200/test/comment/2)?  
> > > > > > parent=1&pretty=true&refresh=true' -d '{"content":"Test Comment"}'  
> > > > > > {  
> > > > > > "ok" : true,  
> > > > > > "\_index" : "test",  
> > > > > > "\_type" : "comment",  
> > > > > > "\_id" : "2",  
> > > > > > "\_version" : 1  
> > > > > > }  
> > > > > > $ curl -s [http://localhost:9200/test/comment/2?pretty=true](http://localhost:9200/test/comment/2?pretty=true)  
> > > > > > {  
> > > > > > "\_index" : "test",  
> > > > > > "\_type" : "comment",  
> > > > > > "\_id" : "2",  
> > > > > > "exists" : false  
> > > > > > }  
> > > > > > $ curl -s [http://localhost:9200/test/comment/\_search?pretty=true](http://localhost:9200/test/comment/_search?pretty=true)  
> > > > > > {  
> > > > > > "took" : 3,  
> > > > > > "timed\_out" : false,  
> > > > > > "\_shards" : {  
> > > > > > "total" : 5,  
> > > > > > "successful" : 5,  
> > > > > > "failed" : 0  
> > > > > > },  
> > > > > > "hits" : {  
> > > > > > "total" : 1,  
> > > > > > "max\_score" : 1.0,  
> > > > > > "hits" : [ {  
> > > > > > "\_index" : "test",  
> > > > > > "\_type" : "comment",  
> > > > > > "\_id" : "2",  
> > > > > > "\_score" : 1.0, "\_source" : {"content":"Test Comment"}  
> > > > > > } ]  
> > > > > > }  
> > > > > > }
> > > > > > 
> > > > > > 1. It seems that I can't look up the document at all when I index it  
> > > > > > with a parent param.
> > > > > > 2. I note that the search result doesn't contain a reference to the  
> > > > > > parent. Is there a way to access the parent when retrieving the doc?
> > > > > > 
> > > > > > Am I doing something wrong?
> > > > > > 
> > > > > > Thanks!  
> > > > > > Mat

---

<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, 3:52am UTC](https://discuss.elastic.co/t/cant-get-document-with-parent-also-can-i-retrieve-its--parent-id/5495/8 "2017-07-06T03:52:49Z")

</div>


