# Index data as nested and flattened to improve aggregation performance?

**URL:** <https://discuss.elastic.co/t/index-data-as-nested-and-flattened-to-improve-aggregation-performance/288799>\
**Category:** Elasticsearch\
**Created:** [November 9, 2021, 4:51pm UTC](https://discuss.elastic.co/t/index-data-as-nested-and-flattened-to-improve-aggregation-performance/288799 "2021-11-09T16:51:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![caseydm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/caseydm/32/26771_2.png) [@caseydm](https://discuss.elastic.co/u/caseydm)\
**Post date:** [November 9, 2021, 4:51pm UTC](https://discuss.elastic.co/t/index-data-as-nested-and-flattened-to-improve-aggregation-performance/288799/1 "2021-11-09T16:51:39Z")

</div>

I am indexing academic papers that have a list of authors. Right now, I index the authors as a nested field type, because we want to query within the list, such as author\_sequence\_number: 1 and author\_display\_name: torrez. We also want to be able to search the author name field so that is set as field type text. What I am realizing is some aggregations on this author data is slow due to nested aggregations.

My idea is to index the author data in two ways, with the second being the flattened data type. That way I have flexibility to aggregate and query off of the flattened version when I do not need to combine fields within a single author. It seems like this would be faster, with a tradeoff in storage space to hold the extra field. Has anybody done something like this and did it work well? Here is an example of my data:

```auto
{
	"fields": {
		"year": [
			2019
		],
		"authors": [{
				"author_display_name.keyword": [
					"jiar kan"
				],
				"author_id": [
					"209777"
				],
				"author_display_name": [
					"Jiar Kan"
				],
				"author_sequence_number": [
					1
				]
			},
			{
				"author_display_name.keyword": [
					"hui jian"
				],
				"author_id": [
					"302777"
				],
				"author_display_name": [
					"Hui Jian"
				],
				"author_sequence_number": [
					2
				]
			}
		],
		"journal.title": [
			"Journal of power electronics"
		],
		"work_id": [
			"3021658105"
		],
		"work_title": [
			"Comparison of Three Active-Frequency-Drift Islanding Detection Methods for Single-Phase Grid-Connected Inverters"
		]
	}
}

```

---

<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 7, 2021, 4:52pm UTC](https://discuss.elastic.co/t/index-data-as-nested-and-flattened-to-improve-aggregation-performance/288799/2 "2021-12-07T16:52:19Z")

</div>

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