# How to denormalize array with huge number of values Elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-to-denormalize-array-with-huge-number-of-values-elasticsearch/293870>\
**Category:** Elasticsearch\
**Created:** [January 10, 2022, 9:52am UTC](https://discuss.elastic.co/t/how-to-denormalize-array-with-huge-number-of-values-elasticsearch/293870 "2022-01-10T09:52:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aldm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aldm/32/45644_2.png) [@aldm](https://discuss.elastic.co/u/aldm)\
**Post date:** [January 10, 2022, 9:52am UTC](https://discuss.elastic.co/t/how-to-denormalize-array-with-huge-number-of-values-elasticsearch/293870/1 "2022-01-10T09:52:51Z")

</div>

Hi,

We're building an app which is using Elasticsearch. For each user there will be followers (array of longs - ids of user who follow this user). With time, number of followers might increase to hundreds of thousands, so I guess that simply storing it in array followers (followers": [1,2,3,...]) will slow the system down significantly and cause memory issues maybe on replication.

What is the best way to handle this?

Is it good approach to create a new index named follow, where each follow document would be in the format

```auto
{
   "follower_id": 1,
   "following_id" : 2
}

```

I would need to get followers\_count and possibly followers for user in some cases where I get user profile. followers\_count can be added as property to users index, but again is it good approach?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![aldm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aldm/32/45644_2.png) [@aldm](https://discuss.elastic.co/u/aldm)\
**Post date:** [January 14, 2022, 3:06pm UTC](https://discuss.elastic.co/t/how-to-denormalize-array-with-huge-number-of-values-elasticsearch/293870/2 "2022-01-14T15:06:55Z")

</div>

Anyone?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [January 16, 2022, 9:03am UTC](https://discuss.elastic.co/t/how-to-denormalize-array-with-huge-number-of-values-elasticsearch/293870/3 "2022-01-16T09:03:26Z")

</div>

Constantly updating a doc containing thousands of ids is not going to be handled efficiently.  
Your multiple-doc approach will be more efficient at writing but could make certain types of analysis harder at query time eg sorting people by numbers of followers.

---

<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:** [February 13, 2022, 9:03am UTC](https://discuss.elastic.co/t/how-to-denormalize-array-with-huge-number-of-values-elasticsearch/293870/4 "2022-02-13T09:03:48Z")

</div>

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