# Include-in-all and include-in-root

**URL:** <https://discuss.elastic.co/t/include-in-all-and-include-in-root/12067>\
**Category:** Elasticsearch\
**Created:** [May 22, 2013, 8:23am UTC](https://discuss.elastic.co/t/include-in-all-and-include-in-root/12067 "2013-05-22T08:23:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chetana](https://avatars.discourse-cdn.com/v4/letter/c/dbc845/32.png) [@Chetana](https://discuss.elastic.co/u/Chetana)\
**Post date:** [May 22, 2013, 8:23am UTC](https://discuss.elastic.co/t/include-in-all-and-include-in-root/12067/1 "2013-05-22T08:23:46Z")

</div>

I am not clear on the usage of include-in-all and include-in-root. Could  
someone please explain with some examples or point to some good references

--  
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:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [May 23, 2013, 10:16am UTC](https://discuss.elastic.co/t/include-in-all-and-include-in-root/12067/2 "2013-05-23T10:16:19Z")

</div>

if you have an array of objects, eg:

{  
followers: [{ user: 1, name "john"}, { user: 2, name: "mary" }  
}

then these get indexed as something like this:

{  
"followers.user": [1,2],  
"followers.name": ["john", "mary"]  
}

But those arrays are actually multi-value fields, which have no intrinsic  
order. they're just "bags" of values. You lose the correlation between  
"user" and "name".

If you set "followers" to be type "nested" instead, then each object is  
indexed as a separate (but externally invisible) document, and so you  
retain the correlation between user and name. And you have to use nested  
queries/filters to access those values. They are not visible in the parent  
doc.

Sometimes, eg for faceting, you want those values to be visible in the  
parent. In this case, set include\_in\_parent to true. This will index each  
nested doc as a separate doc AND index the values into the parent doc (as  
per my example above).

if you have nested objects within nested objects, then the parent of the  
nested\>nested is not the top-level document. In this case, use  
include\_in\_root instead.

clint

On 22 May 2013 10:23, Chetana [ambha.career@gmail.com](mailto:ambha.career@gmail.com) wrote:

> I am not clear on the usage of include-in-all and include-in-root. Could  
> someone please explain with some examples or point to some good references
> 
> --  
> 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).

--  
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:** ![Chetana](https://avatars.discourse-cdn.com/v4/letter/c/dbc845/32.png) [@Chetana](https://discuss.elastic.co/u/Chetana)\
**Post date:** [May 24, 2013, 7:38am UTC](https://discuss.elastic.co/t/include-in-all-and-include-in-root/12067/3 "2013-05-24T07:38:54Z")

</div>

Thanks for the explanation.

1. By specify include\_in\_parent = true or include\_in\_parent =true, Will I  
able to use other querybuilders instead of nestedQuery and also, exclude  
the 'path' in nested or other queries  
2.I could also see one more include\_in\_all. What is the use of include\_in\_all  
?

Thanks  
On Thursday, May 23, 2013 3:46:19 PM UTC+5:30, Clinton Gormley wrote:

> if you have an array of objects, eg:
> 
> {  
> followers: [{ user: 1, name "john"}, { user: 2, name: "mary" }  
> }
> 
> then these get indexed as something like this:
> 
> {  
> "followers.user": [1,2],  
> "followers.name": ["john", "mary"]  
> }
> 
> But those arrays are actually multi-value fields, which have no intrinsic  
> order. they're just "bags" of values. You lose the correlation between  
> "user" and "name".
> 
> If you set "followers" to be type "nested" instead, then each object is  
> indexed as a separate (but externally invisible) document, and so you  
> retain the correlation between user and name. And you have to use nested  
> queries/filters to access those values. They are not visible in the parent  
> doc.
> 
> Sometimes, eg for faceting, you want those values to be visible in the  
> parent. In this case, set include\_in\_parent to true. This will index each  
> nested doc as a separate doc AND index the values into the parent doc (as  
> per my example above).
> 
> if you have nested objects within nested objects, then the parent of the  
> nested\>nested is not the top-level document. In this case, use  
> include\_in\_root instead.
> 
> clint
> 
> On 22 May 2013 10:23, Chetana \<[ambha....@gmail.com](mailto:ambha....@gmail.com) \<javascript:\>\> wrote:
> 
> > I am not clear on the usage of include-in-all and include-in-root. Could  
> > someone please explain with some examples or point to some good references
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [May 24, 2013, 10:40am UTC](https://discuss.elastic.co/t/include-in-all-and-include-in-root/12067/4 "2013-05-24T10:40:00Z")

</div>

On 24 May 2013 09:38, Chetana [ambha.career@gmail.com](mailto:ambha.career@gmail.com) wrote:

> Thanks for the explanation.
> 
> 1. By specify include\_in\_parent = true or include\_in\_parent =true, Will I  
> able to use other querybuilders instead of nestedQuery and also, exclude  
> the 'path' in nested or other queries

Yes. Of course the values in the parent/root doc won't be correlated, but  
it would be as though you had indexed the nested objects as type "nested"  
and as type "object".

> 2.I could also see one more include\_in\_all. What is the use of include\_in\_all  
> ?

ie should the nested values be included in the \_all field

clint

> 

--  
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:** ![btiernay](https://avatars.discourse-cdn.com/v4/letter/b/bb73d2/32.png) [@btiernay](https://discuss.elastic.co/u/btiernay)\
**Post date:** [May 24, 2013, 11:38am UTC](https://discuss.elastic.co/t/include-in-all-and-include-in-root/12067/5 "2013-05-24T11:38:06Z")

</div>

Great explanation as always Clint.

Btw, I highly recommend stealing some of them and embedding them back into  
the ES reference docs as examples 🙂

Thanks again

On Thursday, 23 May 2013 06:16:19 UTC-4, Clinton Gormley wrote:

> if you have an array of objects, eg:
> 
> {  
> followers: [{ user: 1, name "john"}, { user: 2, name: "mary" }  
> }
> 
> then these get indexed as something like this:
> 
> {  
> "followers.user": [1,2],  
> "followers.name": ["john", "mary"]  
> }
> 
> But those arrays are actually multi-value fields, which have no intrinsic  
> order. they're just "bags" of values. You lose the correlation between  
> "user" and "name".
> 
> If you set "followers" to be type "nested" instead, then each object is  
> indexed as a separate (but externally invisible) document, and so you  
> retain the correlation between user and name. And you have to use nested  
> queries/filters to access those values. They are not visible in the parent  
> doc.
> 
> Sometimes, eg for faceting, you want those values to be visible in the  
> parent. In this case, set include\_in\_parent to true. This will index each  
> nested doc as a separate doc AND index the values into the parent doc (as  
> per my example above).
> 
> if you have nested objects within nested objects, then the parent of the  
> nested\>nested is not the top-level document. In this case, use  
> include\_in\_root instead.
> 
> clint
> 
> On 22 May 2013 10:23, Chetana \<[ambha....@gmail.com](mailto:ambha....@gmail.com) \<javascript:\>\> wrote:
> 
> > I am not clear on the usage of include-in-all and include-in-root. Could  
> > someone please explain with some examples or point to some good references
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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:34am UTC](https://discuss.elastic.co/t/include-in-all-and-include-in-root/12067/6 "2017-07-06T02:34:57Z")

</div>


