# Remove \_id field from having fielddata

**URL:** <https://discuss.elastic.co/t/remove-id-field-from-having-fielddata/208595>\
**Category:** Elasticsearch\
**Created:** [November 20, 2019, 2:03am UTC](https://discuss.elastic.co/t/remove-id-field-from-having-fielddata/208595 "2019-11-20T02:03:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![seanziee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/seanziee/32/45151_2.png) [@seanziee](https://discuss.elastic.co/u/seanziee)\
**Post date:** [November 20, 2019, 2:03am UTC](https://discuss.elastic.co/t/remove-id-field-from-having-fielddata/208595/1 "2019-11-20T02:03:19Z")

</div>

I'm currently getting huge fielddata stored in RAM when a user does an aggregation on the \_id field. I'd like to prevent that from happening because it breaks the system down if someone does that. Is there any recommendation on how to do that?

---

<div class="post-metadata">

**Author:** ![Bernt\_Rostad](https://avatars.discourse-cdn.com/v4/letter/b/3ab097/32.png) [@Bernt\_Rostad](https://discuss.elastic.co/u/Bernt_Rostad)\
**Post date:** [November 20, 2019, 10:54am UTC](https://discuss.elastic.co/t/remove-id-field-from-having-fielddata/208595/2 "2019-11-20T10:54:05Z")

</div>

> [@seanziee](#):
>
> Is there any recommendation on how to do that?

Yes, the [official documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-id-field.html) says the following about the \_id field and aggregation and sorting:

> The value of the `_id` field is also accessible in aggregations or for sorting, but doing so is discouraged as it requires to load a lot of data in memory. In case sorting or aggregating on the `_id` field is required, it is advised to duplicate the content of the `_id` field in another field that has `doc_values` enabled.

So you should copy the value of your \_id fields to a new field with `doc_values: true` in the index mapping.

You may also want to read [this interesting blog post](https://www.elastic.co/blog/support-in-the-wild-my-biggest-elasticsearch-problem-at-scale) to understand fielddata and doc\_values.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [November 20, 2019, 12:05pm UTC](https://discuss.elastic.co/t/remove-id-field-from-having-fielddata/208595/3 "2019-11-20T12:05:31Z")

</div>

See also [#49166](https://github.com/elastic/elasticsearch/pull/49166) which will add an option to throw an exception rather than loading fielddata on the `_id` field.

---

<div class="post-metadata">

**Author:** ![seanziee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/seanziee/32/45151_2.png) [@seanziee](https://discuss.elastic.co/u/seanziee)\
**Post date:** [November 20, 2019, 8:28pm UTC](https://discuss.elastic.co/t/remove-id-field-from-having-fielddata/208595/4 "2019-11-20T20:28:00Z")

</div>

@Bernt_Rostad The issue is that I'm using the \_id field to prevent duplicates.. so it's necessary that I use it. I do have the \_id in another field, but the issue is that some users still try to use \_id either intentionally or by accident.

@DavidTurner -- That's exactly what I'm looking for. Surprised that it's an option that's only now going into the stack! Thanks 😃

---

<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 18, 2019, 8:28pm UTC](https://discuss.elastic.co/t/remove-id-field-from-having-fielddata/208595/5 "2019-12-18T20:28:08Z")

</div>

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