# Get child doument by id

**URL:** https://discuss.elastic.co/t/get-child-doument-by-id/7719
**Category:** Elasticsearch
**Created:** [May 16, 2012, 1:48pm UTC](https://discuss.elastic.co/t/get-child-doument-by-id/7719 "2012-05-16T13:48:00Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Yuriy\_Bondaruk](https://avatars.discourse-cdn.com/v4/letter/y/e495f1/32.png) [@Yuriy\_Bondaruk](https://discuss.elastic.co/u/Yuriy_Bondaruk)
#### Post date: [May 16, 2012, 1:48pm UTC](https://discuss.elastic.co/t/get-child-doument-by-id/7719/1 "2012-05-16T13:48:00Z")

</div>

Hi,

I have a problem with getting a child document by it's id. I send GET  
request 'localhost:9200/test-index/ChildItem/41311aa0' and the  
response says that item with the specified id doesn't exist. If use  
\_search query then the document is returning as expected.  
But if I don't use parent/child configuration for ChildItem document  
then GET operation works well.

Why ES doesn't return document by it's id when the parent/child  
configuration is using? Or should I change GET request somehow?

Here is mapping of the child and parent:

```
ChildItem: {
    _routing: {
        required: true
    }
    properties: {
        timestamp: {
            format: dateOptionalTime
            type: date
        }
        process-id: {
            index: not_analyzed
            type: string
        }
    }
    _parent: {
        type: MessageItem
    }
}
MessageItem: {
    properties: {
        timestamp: {
            format: dateOptionalTime
            type: date
        }
        status: {
            index: not_analyzed
            type: string
        }
    }
}
```

---

<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: [May 16, 2012, 7:49pm UTC](https://discuss.elastic.co/t/get-child-doument-by-id/7719/2 "2012-05-16T19:49:32Z")

</div>

Thats because on top of the id of the child document, you need to provide  
the parent id in the parent parameter or the routing parameter. The child  
document ends up being assigned to the same shard as the parent, so getting  
it requires knowledge of the parent id to properly route it.

On Wed, May 16, 2012 at 4:48 PM, Yuriy Bondaruk [bondyk@gmail.com](mailto:bondyk@gmail.com) wrote:

> Hi,
> 
> I have a problem with getting a child document by it's id. I send GET  
> request 'localhost:9200/test-index/ChildItem/41311aa0' and the  
> response says that item with the specified id doesn't exist. If use  
> \_search query then the document is returning as expected.  
> But if I don't use parent/child configuration for ChildItem document  
> then GET operation works well.
> 
> Why ES doesn't return document by it's id when the parent/child  
> configuration is using? Or should I change GET request somehow?
> 
> Here is mapping of the child and parent:
> 
> ChildItem: {  
> \_routing: {  
> required: true  
> }  
> properties: {  
> timestamp: {  
> format: dateOptionalTime  
> type: date  
> }  
> process-id: {  
> index: not\_analyzed  
> type: string  
> }  
> }  
> \_parent: {  
> type: MessageItem  
> }  
> }  
> MessageItem: {  
> properties: {  
> timestamp: {  
> format: dateOptionalTime  
> type: date  
> }  
> status: {  
> index: not\_analyzed  
> type: string  
> }  
> }  
> }

---

<div class="post-metadata">

### Author: ![Yuriy\_Bondaruk](https://avatars.discourse-cdn.com/v4/letter/y/e495f1/32.png) [@Yuriy\_Bondaruk](https://discuss.elastic.co/u/Yuriy_Bondaruk)
#### Post date: [May 16, 2012, 8:14pm UTC](https://discuss.elastic.co/t/get-child-doument-by-id/7719/3 "2012-05-16T20:14:35Z")

</div>

Hi,

Thanks for the answer.

Now I have another questions:

1. Is it possible to search child document in all parent docs by child id  
(I don't know the parent) in realtime (as GET operation)?

2. Can I use GET request with specified parent-id + child-id or only POST  
search?

On Wed, May 16, 2012 at 10:49 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> Thats because on top of the id of the child document, you need to provide  
> the parent id in the parent parameter or the routing parameter. The child  
> document ends up being assigned to the same shard as the parent, so getting  
> it requires knowledge of the parent id to properly route it.
> 
> On Wed, May 16, 2012 at 4:48 PM, Yuriy Bondaruk [bondyk@gmail.com](mailto:bondyk@gmail.com) wrote:
> 
> > Hi,
> > 
> > I have a problem with getting a child document by it's id. I send GET  
> > request 'localhost:9200/test-index/ChildItem/41311aa0' and the  
> > response says that item with the specified id doesn't exist. If use  
> > \_search query then the document is returning as expected.  
> > But if I don't use parent/child configuration for ChildItem document  
> > then GET operation works well.
> > 
> > Why ES doesn't return document by it's id when the parent/child  
> > configuration is using? Or should I change GET request somehow?
> > 
> > Here is mapping of the child and parent:
> > 
> > ChildItem: {  
> > \_routing: {  
> > required: true  
> > }  
> > properties: {  
> > timestamp: {  
> > format: dateOptionalTime  
> > type: date  
> > }  
> > process-id: {  
> > index: not\_analyzed  
> > type: string  
> > }  
> > }  
> > \_parent: {  
> > type: MessageItem  
> > }  
> > }  
> > MessageItem: {  
> > properties: {  
> > timestamp: {  
> > format: dateOptionalTime  
> > type: date  
> > }  
> > status: {  
> > index: not\_analyzed  
> > type: string  
> > }  
> > }  
> > }

--  
Best regards,  
Yuriy Bondaruk

mailto: [yuriy.bondaruk@gmail.com](mailto:yuriy.bondaruk@gmail.com)

---

<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: [May 16, 2012, 10:25pm UTC](https://discuss.elastic.co/t/get-child-doument-by-id/7719/4 "2012-05-16T22:25:21Z")

</div>

On Wed, May 16, 2012 at 11:14 PM, Юрій Іванович Бондарук  
[bondyk@gmail.com](mailto:bondyk@gmail.com)wrote:

> Hi,
> 
> Thanks for the answer.
> 
> Now I have another questions:
> 
> 1. Is it possible to search child document in all parent docs by child id  
> (I don't know the parent) in realtime (as GET operation)?

If you don't know the parent id, then yes, you can do a search for it  
instead.

> 1. Can I use GET request with specified parent-id + child-id or only POST  
> search?

Yes, you can do a GET request to get the child document by its id and the  
parent. Just specify the parent id in the routing parameter. I will add a  
parent parameter option as well...

> On Wed, May 16, 2012 at 10:49 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> 
> > Thats because on top of the id of the child document, you need to provide  
> > the parent id in the parent parameter or the routing parameter. The child  
> > document ends up being assigned to the same shard as the parent, so getting  
> > it requires knowledge of the parent id to properly route it.
> > 
> > On Wed, May 16, 2012 at 4:48 PM, Yuriy Bondaruk [bondyk@gmail.com](mailto:bondyk@gmail.com) wrote:
> > 
> > > Hi,
> > > 
> > > I have a problem with getting a child document by it's id. I send GET  
> > > request 'localhost:9200/test-index/ChildItem/41311aa0' and the  
> > > response says that item with the specified id doesn't exist. If use  
> > > \_search query then the document is returning as expected.  
> > > But if I don't use parent/child configuration for ChildItem document  
> > > then GET operation works well.
> > > 
> > > Why ES doesn't return document by it's id when the parent/child  
> > > configuration is using? Or should I change GET request somehow?
> > > 
> > > Here is mapping of the child and parent:
> > > 
> > > ChildItem: {  
> > > \_routing: {  
> > > required: true  
> > > }  
> > > properties: {  
> > > timestamp: {  
> > > format: dateOptionalTime  
> > > type: date  
> > > }  
> > > process-id: {  
> > > index: not\_analyzed  
> > > type: string  
> > > }  
> > > }  
> > > \_parent: {  
> > > type: MessageItem  
> > > }  
> > > }  
> > > MessageItem: {  
> > > properties: {  
> > > timestamp: {  
> > > format: dateOptionalTime  
> > > type: date  
> > > }  
> > > status: {  
> > > index: not\_analyzed  
> > > type: string  
> > > }  
> > > }  
> > > }
> 
> --  
> Best regards,  
> Yuriy Bondaruk
> 
> mailto: [yuriy.bondaruk@gmail.com](mailto:yuriy.bondaruk@gmail.com)

---

<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: [May 16, 2012, 10:28pm UTC](https://discuss.elastic.co/t/get-child-doument-by-id/7719/5 "2012-05-16T22:28:21Z")

</div>

Here is the issue:  
[Get API: Allow to provide a parent value which automatically set the routing value · Issue #1961 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1961) (for now you can  
simply set the routing value).

On Thu, May 17, 2012 at 1:25 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> On Wed, May 16, 2012 at 11:14 PM, Юрій Іванович Бондарук \<[bondyk@gmail.com](mailto:bondyk@gmail.com)
> 
> > wrote:
> 
> > Hi,
> > 
> > Thanks for the answer.
> > 
> > Now I have another questions:
> > 
> > 1. Is it possible to search child document in all parent docs by child id  
> > (I don't know the parent) in realtime (as GET operation)?
> 
> If you don't know the parent id, then yes, you can do a search for it  
> instead.
> 
> > 1. Can I use GET request with specified parent-id + child-id or only POST  
> > search?
> 
> Yes, you can do a GET request to get the child document by its id and the  
> parent. Just specify the parent id in the routing parameter. I will add a  
> parent parameter option as well...
> 
> > On Wed, May 16, 2012 at 10:49 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> > 
> > > Thats because on top of the id of the child document, you need to  
> > > provide the parent id in the parent parameter or the routing parameter. The  
> > > child document ends up being assigned to the same shard as the parent, so  
> > > getting it requires knowledge of the parent id to properly route it.
> > > 
> > > On Wed, May 16, 2012 at 4:48 PM, Yuriy Bondaruk [bondyk@gmail.com](mailto:bondyk@gmail.com)wrote:
> > > 
> > > > Hi,
> > > > 
> > > > I have a problem with getting a child document by it's id. I send GET  
> > > > request 'localhost:9200/test-index/ChildItem/41311aa0' and the  
> > > > response says that item with the specified id doesn't exist. If use  
> > > > \_search query then the document is returning as expected.  
> > > > But if I don't use parent/child configuration for ChildItem document  
> > > > then GET operation works well.
> > > > 
> > > > Why ES doesn't return document by it's id when the parent/child  
> > > > configuration is using? Or should I change GET request somehow?
> > > > 
> > > > Here is mapping of the child and parent:
> > > > 
> > > > ChildItem: {  
> > > > \_routing: {  
> > > > required: true  
> > > > }  
> > > > properties: {  
> > > > timestamp: {  
> > > > format: dateOptionalTime  
> > > > type: date  
> > > > }  
> > > > process-id: {  
> > > > index: not\_analyzed  
> > > > type: string  
> > > > }  
> > > > }  
> > > > \_parent: {  
> > > > type: MessageItem  
> > > > }  
> > > > }  
> > > > MessageItem: {  
> > > > properties: {  
> > > > timestamp: {  
> > > > format: dateOptionalTime  
> > > > type: date  
> > > > }  
> > > > status: {  
> > > > index: not\_analyzed  
> > > > type: string  
> > > > }  
> > > > }  
> > > > }
> > 
> > --  
> > Best regards,  
> > Yuriy Bondaruk
> > 
> > mailto: [yuriy.bondaruk@gmail.com](mailto:yuriy.bondaruk@gmail.com)

---

<div class="post-metadata">

### Author: ![Yuriy\_Bondaruk](https://avatars.discourse-cdn.com/v4/letter/y/e495f1/32.png) [@Yuriy\_Bondaruk](https://discuss.elastic.co/u/Yuriy_Bondaruk)
#### Post date: [May 17, 2012, 7:05am UTC](https://discuss.elastic.co/t/get-child-doument-by-id/7719/6 "2012-05-17T07:05:35Z")

</div>

Thanks for the enhancement. It works well!

On Thu, May 17, 2012 at 1:28 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> Here is the issue:  
> [Get API: Allow to provide a parent value which automatically set the routing value · Issue #1961 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1961) (for now you  
> can simply set the routing value).
> 
> On Thu, May 17, 2012 at 1:25 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> 
> > On Wed, May 16, 2012 at 11:14 PM, Юрій Іванович Бондарук \<  
> > [bondyk@gmail.com](mailto:bondyk@gmail.com)\> wrote:
> > 
> > > Hi,
> > > 
> > > Thanks for the answer.
> > > 
> > > Now I have another questions:
> > > 
> > > 1. Is it possible to search child document in all parent docs by child  
> > > id (I don't know the parent) in realtime (as GET operation)?
> > 
> > If you don't know the parent id, then yes, you can do a search for it  
> > instead.
> > 
> > > 1. Can I use GET request with specified parent-id + child-id or only  
> > > POST search?
> > 
> > Yes, you can do a GET request to get the child document by its id and the  
> > parent. Just specify the parent id in the routing parameter. I will add a  
> > parent parameter option as well...
> > 
> > > On Wed, May 16, 2012 at 10:49 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> > > 
> > > > Thats because on top of the id of the child document, you need to  
> > > > provide the parent id in the parent parameter or the routing parameter. The  
> > > > child document ends up being assigned to the same shard as the parent, so  
> > > > getting it requires knowledge of the parent id to properly route it.
> > > > 
> > > > On Wed, May 16, 2012 at 4:48 PM, Yuriy Bondaruk [bondyk@gmail.com](mailto:bondyk@gmail.com)wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > I have a problem with getting a child document by it's id. I send GET  
> > > > > request 'localhost:9200/test-index/ChildItem/41311aa0' and the  
> > > > > response says that item with the specified id doesn't exist. If use  
> > > > > \_search query then the document is returning as expected.  
> > > > > But if I don't use parent/child configuration for ChildItem document  
> > > > > then GET operation works well.
> > > > > 
> > > > > Why ES doesn't return document by it's id when the parent/child  
> > > > > configuration is using? Or should I change GET request somehow?
> > > > > 
> > > > > Here is mapping of the child and parent:
> > > > > 
> > > > > ChildItem: {  
> > > > > \_routing: {  
> > > > > required: true  
> > > > > }  
> > > > > properties: {  
> > > > > timestamp: {  
> > > > > format: dateOptionalTime  
> > > > > type: date  
> > > > > }  
> > > > > process-id: {  
> > > > > index: not\_analyzed  
> > > > > type: string  
> > > > > }  
> > > > > }  
> > > > > \_parent: {  
> > > > > type: MessageItem  
> > > > > }  
> > > > > }  
> > > > > MessageItem: {  
> > > > > properties: {  
> > > > > timestamp: {  
> > > > > format: dateOptionalTime  
> > > > > type: date  
> > > > > }  
> > > > > status: {  
> > > > > index: not\_analyzed  
> > > > > type: string  
> > > > > }  
> > > > > }  
> > > > > }
> > > 
> > > --  
> > > Best regards,  
> > > Yuriy Bondaruk
> > > 
> > > mailto: [yuriy.bondaruk@gmail.com](mailto:yuriy.bondaruk@gmail.com)

--  
Best regards,  
Yuriy Bondaruk

---

<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:28am UTC](https://discuss.elastic.co/t/get-child-doument-by-id/7719/7 "2017-07-06T03:28:23Z")

</div>


