# Creating a scripted field that returns the \_Id field value

**URL:** <https://discuss.elastic.co/t/creating-a-scripted-field-that-returns-the-id-field-value/110147>\
**Category:** Kibana\
**Created:** [December 4, 2017, 12:51pm UTC](https://discuss.elastic.co/t/creating-a-scripted-field-that-returns-the-id-field-value/110147 "2017-12-04T12:51:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![veronica\_rivas](https://avatars.discourse-cdn.com/v4/letter/v/49beb7/32.png) [@veronica\_rivas](https://discuss.elastic.co/u/veronica_rivas)\
**Post date:** [December 4, 2017, 12:51pm UTC](https://discuss.elastic.co/t/creating-a-scripted-field-that-returns-the-id-field-value/110147/1 "2017-12-04T12:51:07Z")

</div>

Hi there!!!

I want to create a scripted field that returns the "\_id" field value, in order to visualize it in a table with the information of each log, but I'm not being able to solve it so far.

I tried to do it using params['\_id'] (that returns "-") and doc['\_id'].value (that obviously returns an error).

Do anyone know how to do it?  
Thank you so much in advance for your help.

---

<div class="post-metadata">

**Author:** ![weltenwort](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/weltenwort/32/53885_2.png) [@weltenwort](https://discuss.elastic.co/u/weltenwort)\
**Post date:** [December 5, 2017, 3:57pm UTC](https://discuss.elastic.co/t/creating-a-scripted-field-that-returns-the-id-field-value/110147/2 "2017-12-05T15:57:54Z")

</div>

Hi @veronica_rivas,

a scripted field with the painless expression `doc['_id'].value` worked for me. Which version of the Elastic Stack are you using?

(Also, why not use the `_id` field directly?)

---

<div class="post-metadata">

**Author:** ![veronica\_rivas](https://avatars.discourse-cdn.com/v4/letter/v/49beb7/32.png) [@veronica\_rivas](https://discuss.elastic.co/u/veronica_rivas)\
**Post date:** [December 6, 2017, 1:23pm UTC](https://discuss.elastic.co/t/creating-a-scripted-field-that-returns-the-id-field-value/110147/3 "2017-12-06T13:23:02Z")

</div>

Hi @weltenwort,

I'm using the version 5.2.2, and with doc['\_id'].value I got this error: "Field Data access on the \_uid field is disallowed". So, I changed it for doc['\_iud'].value and now it works.

P.D: This one gives me the type name and the id, so I splited the string to have only the\_Id.

And I couldn't be able to use the \_id field directly as a new split row because it doesn't show up in "aggregation =\> terms =\> seleted field" =(

Thank you so much for answering !!!! 🙂

---

<div class="post-metadata">

**Author:** ![weltenwort](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/weltenwort/32/53885_2.png) [@weltenwort](https://discuss.elastic.co/u/weltenwort)\
**Post date:** [December 7, 2017, 5:42pm UTC](https://discuss.elastic.co/t/creating-a-scripted-field-that-returns-the-id-field-value/110147/4 "2017-12-07T17:42:36Z")

</div>

In newer versions the `_id` field is available for aggreations:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/6/4689078a81c3aa2b45dd96fc43ac177d39848dd6.png)

It does not perform well on large databases though due to the lack of docvalue support for that field.

Good to hear that you have found a solution for your version.

---

<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:** [January 4, 2018, 5:42pm UTC](https://discuss.elastic.co/t/creating-a-scripted-field-that-returns-the-id-field-value/110147/5 "2018-01-04T17:42:42Z")

</div>

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