# Nested vs Encoded Array

**URL:** <https://discuss.elastic.co/t/nested-vs-encoded-array/120089>\
**Category:** Elasticsearch\
**Created:** [February 15, 2018, 11:54pm UTC](https://discuss.elastic.co/t/nested-vs-encoded-array/120089 "2018-02-15T23:54:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HJewkes](https://avatars.discourse-cdn.com/v4/letter/h/c67d28/32.png) [@HJewkes](https://discuss.elastic.co/u/HJewkes)\
**Post date:** [February 15, 2018, 11:54pm UTC](https://discuss.elastic.co/t/nested-vs-encoded-array/120089/1 "2018-02-15T23:54:06Z")

</div>

Currently, my mapping queries against an array of nested objects with 3 fields (call them A, B, and C). Our query pattern either filters by (A), by (A & B), or by (A, B, & C). We also may perform a terms aggregation on C when filtered to (A) or (A & B).

Given that we never filter by (B) or (C) individually, I am curious whether it may be more performant to change from the nested object array to a single array encoding the values together, for instance: ["A", "A:B", "A:C", "A:B:C"], and then using the same encoding scheme when querying. Regarding the terms aggregation, I would need to either use a script to prune the terms to only those starting with the filtered encoding, or I could calculate for all terms and then prune the result set. I'm not sure which would be more performant.

However, is this an over optimization?

---

<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:** [March 15, 2018, 11:54pm UTC](https://discuss.elastic.co/t/nested-vs-encoded-array/120089/2 "2018-03-15T23:54:07Z")

</div>

Closed on March 15, 2018, 11:54pm UTC

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