# Access index id in scripted field

**URL:** <https://discuss.elastic.co/t/access-index-id-in-scripted-field/146909>\
**Category:** Kibana\
**Created:** [August 31, 2018, 7:31pm UTC](https://discuss.elastic.co/t/access-index-id-in-scripted-field/146909 "2018-08-31T19:31:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![caub](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/caub/32/33783_2.png) [@caub](https://discuss.elastic.co/u/caub)\
**Post date:** [August 31, 2018, 7:31pm UTC](https://discuss.elastic.co/t/access-index-id-in-scripted-field/146909/1 "2018-08-31T19:31:02Z")

</div>

I'd like to create a scripted field URL, linking to the context of an event

The context links look like: `#/context/982353c0-ac85-11e8-a1c9-1f53c4cb4ccc/doc/LS9okWUBoR_D7GtSWhbM?_a=(columns:!(docker.container.name,err.message,err.stack),filters:!(),predecessorCount:5,sort:!('@timestamp',desc),successorCount:5)&_g=(filters:!())`

`982353c0-ac85-11e8-a1c9-1f53c4cb4ccc` is the current index id (I guess), I'd like to not hardcode it

I tried to do:

Link pattern:

```auto
#/context/{{rawValue}}?_a=(columns:!(docker.container.name,err.message,err.stack),filters:!(),predecessorCount:5,sort:!('@timestamp',desc),successorCount:5)&_g=(filters:!())

```

Script:

```auto
doc['_index'].value + '/doc/' + doc['_id'].value

```

This give links like: `#/context/filebeat-6.4.0-2018.08.30/doc/LS9okWUBoR_D7GtSWhbM?_a...` but they don't link correctly

So I need to figure what that `982353c0-ac85-11e8-a1c9-1f53c4cb4ccc` is, and how it can be accessed

When I look at 2 elasticsearch indexes

```auto
      "provided_name": "filebeat-6.4.0-2018.08.30",
      "creation_date": "1535654788427",
      "number_of_replicas": "1",
      "uuid": "8mfJNvygSry5DqjCSo-fZQ",

      "provided_name": "filebeat-6.4.0-2018.08.31",
      "creation_date": "1535713413751",
      "number_of_replicas": "1",
      "uuid": "Css9QSqaQG62W3TEtL8yhQ",

```

Their uuids don't match that value

```auto
> Buffer.from('982353c0-ac85-11e8-a1c9-1f53c4cb4ccc'.replace(/-/g, ''), 'hex').toString('base64')
'mCNTwKyFEeihyR9TxMtMzA=='

```

---

<div class="post-metadata">

**Author:** ![Harshad\_Velapure](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harshad_velapure/32/33684_2.png) [@Harshad\_Velapure](https://discuss.elastic.co/u/Harshad_Velapure)\
**Post date:** [August 31, 2018, 8:48pm UTC](https://discuss.elastic.co/t/access-index-id-in-scripted-field/146909/2 "2018-08-31T20:48:01Z")

</div>

Hello

I tried that script and got expected output  
field - testfield  
value - indexName-2018.08.31/doc/7e62f4ae5e9da12633c55581e46040721b61c408

can you check if you are getting uniq \_id in each log?

---

<div class="post-metadata">

**Author:** ![caub](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/caub/32/33783_2.png) [@caub](https://discuss.elastic.co/u/caub)\
**Post date:** [September 1, 2018, 2:35pm UTC](https://discuss.elastic.co/t/access-index-id-in-scripted-field/146909/3 "2018-09-01T14:35:59Z")

</div>

Thanks, that script work indeed, but not the `#/context/SOME_ID/doc/DOC_ID?....` link

SOME\_ID isn't the index id as I thought

You can get those links from the **discover** tab:

 ![2018-09-02-002129_1110x220_scrot](https://us1.discourse-cdn.com/elastic/original/3X/8/9/89f56d8c58e3995f57c1ce35c6fe3e22cc1eb279.png)

The question is really what is `SOME_ID` there? I'm going to hardcode it for now, but I feel it's bad

---

<div class="post-metadata">

**Author:** ![caub](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/caub/32/33783_2.png) [@caub](https://discuss.elastic.co/u/caub)\
**Post date:** [September 4, 2018, 1:30pm UTC](https://discuss.elastic.co/t/access-index-id-in-scripted-field/146909/4 "2018-09-04T13:30:46Z")

</div>

solved in [What is the ID in documents or surrounding documents links?](https://discuss.elastic.co/t/what-is-the-id-in-documents-or-surrounding-documents-links/147115/4)

---

<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:** [October 2, 2018, 1:30pm UTC](https://discuss.elastic.co/t/access-index-id-in-scripted-field/146909/5 "2018-10-02T13:30:49Z")

</div>

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