# Update Nested Document

**URL:** <https://discuss.elastic.co/t/update-nested-document/5079>\
**Category:** Elasticsearch\
**Created:** [August 8, 2011, 11:34am UTC](https://discuss.elastic.co/t/update-nested-document/5079 "2011-08-08T11:34:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicolas\_Lalevee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_lalevee/32/2892_2.png) [@Nicolas\_Lalevee](https://discuss.elastic.co/u/Nicolas_Lalevee)\
**Post date:** [August 8, 2011, 11:34am UTC](https://discuss.elastic.co/t/update-nested-document/5079/1 "2011-08-08T11:34:46Z")

</div>

First, my context: I have some "topics", in which there are some "posts". Both are indexed and today I search in both separately [1]. To improve the user experience, I want to search in both whereas showing a single page of result of topics. When hit on topics, add the topic to the results. When hit on a post, add the owning topic to the result and show the highlighted post.

For that use case, nested queries seems to be the perfect tool (apart from the post highlight, guessing that I may be able to help implement something about it).  
I don't remember where in the doc but it was stated that nested document cannot be updated individually, separately from their parent document. That is a blocker for me, I would have too many nested document per root document. I have some topics which have more than thousand posts, and these topics are updated the most frequently.

So I dug into the code to understand the limitation, to understand if what I want to implement is just feasible. But I didn't find anything meaningful. Could someone explain it to me ?

cheers,  
Nicolas

[1] [http://www.scoop.it/search#q=sport&page=3&offset=10&limit=10&isAfterLastPageNumOfShortest=false](http://www.scoop.it/search#q=sport&page=3&offset=10&limit=10&isAfterLastPageNumOfShortest=false)

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [August 8, 2011, 12:11pm UTC](https://discuss.elastic.co/t/update-nested-document/5079/2 "2011-08-08T12:11:55Z")

</div>

Hi Nicolas

> I don't remember where in the doc but it was stated that nested  
> document cannot be updated individually, separately from their parent  
> document. That is a blocker for me, I would have too many nested  
> document per root document. I have some topics which have more than  
> thousand posts, and these topics are updated the most frequently.

You may want to look at parent/child queries instead.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

clint

---

<div class="post-metadata">

**Author:** ![Nicolas\_Lalevee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_lalevee/32/2892_2.png) [@Nicolas\_Lalevee](https://discuss.elastic.co/u/Nicolas_Lalevee)\
**Post date:** [August 8, 2011, 4:07pm UTC](https://discuss.elastic.co/t/update-nested-document/5079/3 "2011-08-08T16:07:48Z")

</div>

Le 8 août 2011 à 14:11, Clinton Gormley a écrit :

> Hi Nicolas
> 
> > I don't remember where in the doc but it was stated that nested  
> > document cannot be updated individually, separately from their parent  
> > document. That is a blocker for me, I would have too many nested  
> > document per root document. I have some topics which have more than  
> > thousand posts, and these topics are updated the most frequently.
> 
> You may want to look at parent/child queries instead.
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/parent-field.html)  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/top-children-query.html)

For what I could read, I don't remember where again (maybe just a user feedback), these kind of queries are quite slow compared to the nested ones. I'll look closer to them. Thanks for the pointers.

And after a second deeper look into the code, I think I finally understand how the BlockJoinQuery works. To be efficient, documents have to be ordered accordingly, the children before the owing parent. It avoids any lookup in Lucene to get the parent of a child. Quite smart by the way !

cheers,  
Nicolas

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [August 8, 2011, 4:20pm UTC](https://discuss.elastic.co/t/update-nested-document/5079/4 "2011-08-08T16:20:34Z")

</div>

Hi Nicolas

> > You may want to look at parent/child queries instead.
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/parent-field.html)  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/top-children-query.html)
> 
> For what I could read, I don't remember where again (maybe just a user  
> feedback), these kind of queries are quite slow compared to the nested  
> ones. I'll look closer to them. Thanks for the pointers.

They are slower. Whether they are too slow or not depends on your  
experience with them. ES needs to run two queries: one for the child  
docs, then one for the parents. That said, child docs are stored on the  
same shard as the parent docs, so that is already optimized.

It's a toss up between wanting to query parent/child docs together, and  
not wanting to reindex the parent doc every time a child is updated 🙂

clint

---

<div class="post-metadata">

**Author:** ![Nicolas\_Lalevee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_lalevee/32/2892_2.png) [@Nicolas\_Lalevee](https://discuss.elastic.co/u/Nicolas_Lalevee)\
**Post date:** [August 8, 2011, 4:43pm UTC](https://discuss.elastic.co/t/update-nested-document/5079/5 "2011-08-08T16:43:15Z")

</div>

Le 8 août 2011 à 18:20, Clinton Gormley a écrit :

> Hi Nicolas
> 
> > > You may want to look at parent/child queries instead.
> > > 
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/parent-field.html)  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/top-children-query.html)
> > 
> > For what I could read, I don't remember where again (maybe just a user  
> > feedback), these kind of queries are quite slow compared to the nested  
> > ones. I'll look closer to them. Thanks for the pointers.
> 
> They are slower. Whether they are too slow or not depends on your  
> experience with them. ES needs to run two queries: one for the child  
> docs, then one for the parents. That said, child docs are stored on the  
> same shard as the parent docs, so that is already optimized.
> 
> It's a toss up between wanting to query parent/child docs together, and  
> not wanting to reindex the parent doc every time a child is updated 🙂

I guess that last sentence sum up the problematic very well.  
Now I'll try to make a choice with some tests 🙂

Thanks  
Nicolas

---

<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:57am UTC](https://discuss.elastic.co/t/update-nested-document/5079/6 "2017-07-06T03:57:56Z")

</div>


