# Aggregation on flattened fields slows down due bulk writing

**URL:** <https://discuss.elastic.co/t/aggregation-on-flattened-fields-slows-down-due-bulk-writing/320149>\
**Category:** Elasticsearch\
**Created:** [November 30, 2022, 12:01pm UTC](https://discuss.elastic.co/t/aggregation-on-flattened-fields-slows-down-due-bulk-writing/320149 "2022-11-30T12:01:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Asym](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@Asym](https://discuss.elastic.co/u/Asym)\
**Post date:** [November 30, 2022, 12:01pm UTC](https://discuss.elastic.co/t/aggregation-on-flattened-fields-slows-down-due-bulk-writing/320149/1 "2022-11-30T12:01:07Z")

</div>

Hi!

While working with aggregation on flattened fields, we encountered a problem.  
We have a cluster, with 3 nodes, number of shards - 10, number of replicas - 2 and ~7 mln documents.  
Average aggregation (with flattened fields) takes 300-500ms, but when we enable kafka consumer which begins bulk writing - aggregations on flattened fields significantly slows down to 7-8 seconds.

So constant bulk writing affects on aggregation only on flattened fields, what could be causing this situation and how to fix it?

Thanks!

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [November 30, 2022, 12:21pm UTC](https://discuss.elastic.co/t/aggregation-on-flattened-fields-slows-down-due-bulk-writing/320149/2 "2022-11-30T12:21:06Z")

</div>

What is the specification of the cluster and hardware used? What type of storage are you using? What does `iostat -x` show if you query with and without indexing?

---

<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 28, 2022, 12:21pm UTC](https://discuss.elastic.co/t/aggregation-on-flattened-fields-slows-down-due-bulk-writing/320149/3 "2022-12-28T12:21:59Z")

</div>

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