# Would making a document non-nested improve query performance?

**URL:** <https://discuss.elastic.co/t/would-making-a-document-non-nested-improve-query-performance/155801>\
**Category:** Elasticsearch\
**Created:** [November 8, 2018, 12:22am UTC](https://discuss.elastic.co/t/would-making-a-document-non-nested-improve-query-performance/155801 "2018-11-08T00:22:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxshortzp](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@maxshortzp](https://discuss.elastic.co/u/maxshortzp)\
**Post date:** [November 8, 2018, 12:22am UTC](https://discuss.elastic.co/t/would-making-a-document-non-nested-improve-query-performance/155801/1 "2018-11-08T00:22:30Z")

</div>

I'm working with some legacy code that has nested documents that have 1 field each.

I have profile results that show that a large amount of time is sometimes spent querying the nested field.

If I move to a single analyzed string field (and use [position increment gap](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/position-increment-gap.html#position-increment-gap)) I should see substantial performance improvement, right?

**I'm mostly looking for information on what (if anything) makes nested queries on single documents more expensive than queries on fields in a flat document.**

Possibly related:

> [@Poor Query Performance using nested document structure](https://discuss.elastic.co/t/poor-query-performance-using-nested-document-structure/130781/7):
>
> So you have a lot of nested docs here which is causing lot of internal "joins" at search time. Few things I can think about: First once the segments are loaded in memory (if you have enough memory left for the OS FS Cache), hopefully this will be much faster. May be having more shards in that case with fewer documents per shard would help to reduce that time Depending on your use case, don't use nested when not absolutely necessary. But may be @jpountz has other ideas?

---

<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:** [December 6, 2018, 12:22am UTC](https://discuss.elastic.co/t/would-making-a-document-non-nested-improve-query-performance/155801/2 "2018-12-06T00:22:32Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
