# Use the index name in a scripted field

**URL:** <https://discuss.elastic.co/t/use-the-index-name-in-a-scripted-field/263496>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [February 6, 2021, 12:30pm UTC](https://discuss.elastic.co/t/use-the-index-name-in-a-scripted-field/263496 "2021-02-06T12:30:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shalhevet](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Shalhevet](https://discuss.elastic.co/u/Shalhevet)\
**Post date:** [February 6, 2021, 12:30pm UTC](https://discuss.elastic.co/t/use-the-index-name-in-a-scripted-field/263496/1 "2021-02-06T12:30:46Z")

</div>

I want to create a scripted field in an index pattern which takes the first word of the index's name and concatenate to it another value.  
How can I access the name of the index via painless in the scripted field?  
for example:  
index name= 'x1-index\*'  
scripted field=x1+'\_'+doc.['some\_string'].value

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [February 6, 2021, 2:02pm UTC](https://discuss.elastic.co/t/use-the-index-name-in-a-scripted-field/263496/2 "2021-02-06T14:02:44Z")

</div>

Try this to access the name.

```auto
String idxName = doc['_index'].value;

return idxName;

```

---

<div class="post-metadata">

**Author:** ![Shalhevet](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Shalhevet](https://discuss.elastic.co/u/Shalhevet)\
**Post date:** [February 6, 2021, 3:52pm UTC](https://discuss.elastic.co/t/use-the-index-name-in-a-scripted-field/263496/3 "2021-02-06T15:52:47Z")

</div>

it is working!  
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:** [March 6, 2021, 3:52pm UTC](https://discuss.elastic.co/t/use-the-index-name-in-a-scripted-field/263496/4 "2021-03-06T15:52:57Z")

</div>

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