# Nested Document vs Single/Separate Document query!

**URL:** <https://discuss.elastic.co/t/nested-document-vs-single-separate-document-query/55469>\
**Category:** Elasticsearch\
**Created:** [July 14, 2016, 5:12am UTC](https://discuss.elastic.co/t/nested-document-vs-single-separate-document-query/55469 "2016-07-14T05:12:10Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gugansankar](https://avatars.discourse-cdn.com/v4/letter/g/e274bd/32.png) [@gugansankar](https://discuss.elastic.co/u/gugansankar)\
**Post date:** [July 14, 2016, 5:12am UTC](https://discuss.elastic.co/t/nested-document-vs-single-separate-document-query/55469/1 "2016-07-14T05:12:10Z")

</div>

Not sure , whether this question is asked already. But I couldn't find similar question and answer.

Currently I'm preparing the log structure to store it in Elasticsearch. for that, I would like to know which one is perfect for long time search [1 year data] "Nested document" or "Single Document".  
Whether I could see any slowness when query nested document over 1 year time period.

Which one I would prefer for my log structure either Nested or Single document ?

Below is the example of SINGLE Nested Document:

{"web1":{"test01":{"Uptime":277887,"Name":"test01","TotalOutput":0,"TotalOutputRate":0,"Cal":{"C1":0,"S1":0,"M1":0,"S1":0,"R1":0,"R2":0},"TotalConnections":0,"TotalInputRate":0,"TotalInput":0},"Uptime":606934,"TotalInputRate":611695,"app102\_02":{"Uptime":500891,"Name":"app102\_02","TotalOutput":0,"TotalOutputRate":0,"Cal":{"C1":0,"S1":0,"M1":0,"S1":0,"R1":0,"R2":0},"TotalConnections":0,"TotalInputRate":0,"TotalInput":0},"timestamp":"2016-06-20 09:53:34","app102\_01":{"Uptime":336537,"Name":"app102\_01","TotalOutput":254245747,"TotalOutputRate":92544,"Cal":{"C1":0,"S1":0,"M1":0,"S1":0,"R1":0,"R2":1},"TotalConnections":1,"TotalInputRate":91536,"TotalInput":16542639433},"test02":{"Uptime":18346,"Name":"test02","TotalOutput":0,"TotalOutputRate":0,"Cal":{"C1":0,"S1":0,"M1":0,"S1":0,"R1":0,"R2":0},"TotalConnections":0,"TotalInputRate":0,"TotalInput":0},"app203\_01":{"Uptime":65969,"Name":"app203\_01","TotalOutput":5622464792,"TotalOutputRate":85467,"Cal":{"C1":0,"S1":0,"M1":0,"S1":0,"R1":0,"R2":1},"TotalConnections":1,"TotalInputRate":84711,"TotalInput":5567492307},"app202\_01":{"Uptime":6050,"Name":"app202\_01","TotalOutput":298164476,"TotalOutputRate":88098,"Cal":{"C1":0,"S1":0,"M1":0,"S1":0,"R1":0,"R2":1},"TotalConnections":1,"TotalInputRate":87159,"TotalInput":528620329},"app31":{"Uptime":18424,"Name":"app31","TotalOutput":0,"TotalOutputRate":0,"Cal":{"C1":0,"S1":0,"M1":0,"S1":0,"R1":0,"R2":0},"TotalConnections":0,"TotalInputRate":0,"TotalInput":0},"app101\_01":{"Uptime":5897,"Name":"app101\_01","TotalOutput":488257431,"TotalOutputRate":83028,"Cal":{"C1":0,"S1":0,"M1":0,"S1":0,"R1":0,"R2":1},"TotalConnections":1,"TotalInputRate":82129,"TotalInput":484619739},"TotalInput":355511505764,"Cal":{"C1":0,"S1":0,"M1":0,"S1":0,"DVRCHUNKS":0,"R1":3,"WEBM":0,"R2":7},"TotalOutput":563728749361,"cambtest01\_01":{"Uptime":181258,"Name":"cambtest01\_01","TotalOutput":6373160103,"TotalOutputRate":183271,"Cal":{"C1":0,"S1":0,"M1":0,"S1":0,"R1":1,"R2":1},"TotalConnections":2,"TotalInputRate":91219,"TotalInput":16533919303},"TotalOutputRate":721560,"App":"web1","TotalConnections":10,"app204\_01":{"Uptime":65970,"Name":"app204\_01","TotalOutput":5622069756,"TotalOutputRate":85059,"Cal":{"C1":0,"S1":0,"M1":0,"S1":0,"R1":0,"R2":1},"TotalConnections":1,"TotalInputRate":84218,"TotalInput":5567236176},"app201\_01":{"Uptime":65980,"Name":"app201\_01","TotalOutput":5823095542,"TotalOutputRate":87995,"Cal":{"C1":0,"S1":0,"M1":0,"S1":0,"R1":0,"R2":1},"TotalConnections":1,"TotalInputRate":87503,"TotalInput":5766095725},"test02wheel":{"Uptime":18357,"Name":"test02wheel","TotalOutput":0,"TotalOutputRate":0,"Cal":{"C1":0,"S1":0,"M1":0,"S1":0,"R1":1,"R2":0},"TotalConnections":1,"TotalInputRate":0,"TotalInput":0},"app32":{"Uptime":18380,"Name":"app32","TotalOutput":0,"TotalOutputRate":0,"Cal":{"C1":0,"S1":0,"M1":0,"S1":0,"R1":1,"R2":0},"TotalConnections":1,"TotalInputRate":0,"TotalInput":0}},"@version":"1","@timestamp":"2016-06-20T09:53:36.075Z","host":"10.11.12.202","port":38229,"type":"application1" }

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 14, 2016, 5:38am UTC](https://discuss.elastic.co/t/nested-document-vs-single-separate-document-query/55469/2 "2016-07-14T05:38:02Z")

</div>

Please format your code.

It depends on what you are searching for. As a response, are you expecting to see the full document or only a single line of the document?

If the later, I'd copy into each single line, the "parent" values.

If the former, I'd go for nested docs.

---

<div class="post-metadata">

**Author:** ![gugansankar](https://avatars.discourse-cdn.com/v4/letter/g/e274bd/32.png) [@gugansankar](https://discuss.elastic.co/u/gugansankar)\
**Post date:** [July 14, 2016, 6:14am UTC](https://discuss.elastic.co/t/nested-document-vs-single-separate-document-query/55469/3 "2016-07-14T06:14:19Z")

</div>

Sorry I tried to upload the code in formatted one. But it not accepted more than 5000 lines in forum. that's why I updated as a minify json.

**It depends on what you are searching for. As a response, are you expecting to see the full document or only a single line of the document?**

- I expected a response as a single value from the document like value **277887** from " **web1.test01.uptime**".

**If the later, I'd copy into each single line, the "parent" values.**  
**If the former, I'd go for nested docs.**

- 

```
 Sorry,I couldn't understand. Please share more info.
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 14, 2016, 7:28pm UTC](https://discuss.elastic.co/t/nested-document-vs-single-separate-document-query/55469/4 "2016-07-14T19:28:14Z")

</div>

I'd index data like:

```auto
PUT index/doc/test01
{
   "Uptime":277887,
   "Name":"test01",
   "TotalOutput":0,
   "TotalOutputRate":0,
   "Cal":{
      "C1":0,
      "S1":0,
      "M1":0,
      "S1":0,
      "R1":0,
      "R2":0
   },
   "TotalConnections":0,
   "TotalInputRate":0,
   "TotalInput":0
}

```

Warning: `S1` is a duplicated key, which is wrong.

---

<div class="post-metadata">

**Author:** ![gugansankar](https://avatars.discourse-cdn.com/v4/letter/g/e274bd/32.png) [@gugansankar](https://discuss.elastic.co/u/gugansankar)\
**Post date:** [July 15, 2016, 10:12am UTC](https://discuss.elastic.co/t/nested-document-vs-single-separate-document-query/55469/5 "2016-07-15T10:12:45Z")

</div>

Sorry, that should be S1 and S2. May be I posted a testing data that still not finalized to insert into Elasticsearch.

Could you please share which one will be fit for long term [1 year] ?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 19, 2016, 8:52am UTC](https://discuss.elastic.co/t/nested-document-vs-single-separate-document-query/55469/6 "2016-07-19T08:52:40Z")

</div>

> [@gugansankar](#):
>
> Could you please share which one will be fit for long term [1 year] ?

I wrote this: [Nested Document vs Single/Separate Document query! - #4 by dadoonet](https://discuss.elastic.co/t/nested-document-vs-single-separate-document-query/55469/4)

---

<div class="post-metadata">

**Author:** ![gugansankar](https://avatars.discourse-cdn.com/v4/letter/g/e274bd/32.png) [@gugansankar](https://discuss.elastic.co/u/gugansankar)\
**Post date:** [July 19, 2016, 9:55am UTC](https://discuss.elastic.co/t/nested-document-vs-single-separate-document-query/55469/7 "2016-07-19T09:55:16Z")

</div>

Do you mean, keep it as a separate documents instead of put entire thing in a single document ?.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 19, 2016, 10:42am UTC](https://discuss.elastic.co/t/nested-document-vs-single-separate-document-query/55469/8 "2016-07-19T10:42:48Z")

</div>

Yes. That's what I meant.

---

<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 5, 2017, 10:34pm UTC](https://discuss.elastic.co/t/nested-document-vs-single-separate-document-query/55469/9 "2017-07-05T22:34:26Z")

</div>


