# Scripted URL field of optional field

**URL:** <https://discuss.elastic.co/t/scripted-url-field-of-optional-field/345245>\
**Category:** Kibana\
**Created:** [October 17, 2023, 8:26pm UTC](https://discuss.elastic.co/t/scripted-url-field-of-optional-field/345245 "2023-10-17T20:26:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bohdan\_Dubyk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bohdan_dubyk/32/126611_2.png) [@Bohdan\_Dubyk](https://discuss.elastic.co/u/Bohdan_Dubyk)\
**Post date:** [October 17, 2023, 8:26pm UTC](https://discuss.elastic.co/t/scripted-url-field-of-optional-field/345245/1 "2023-10-17T20:26:01Z")

</div>

Some of my logs/documents contain request information, and one of the fields is `message.request_id`, so that field does not exist on every document.

What I want to achieve is to add a Scripted Field of URL type, that'll lead to logs and filter logs by that request-id, basically linking to an immediately filtered log where I can see all the logs related to the particular request. The main reason why I want is to use the field in the data table.

The issue is that I'm new to Scripted Fields and in my case, after I create that custom field I can't see. any logs.

Here is how I'm creating that field:

 ![Screenshot 2023-10-17 at 23.23.06](https://us1.discourse-cdn.com/elastic/original/3X/6/7/679ca0bff140dde046dc3f6e482067b0e473b8e8.png)

In the Discovery section, I can see that newly created field, but all other index-related fields are gone and no document is displayed.

What I'm doing wrong?

---

<div class="post-metadata">

**Author:** ![jughosta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jughosta/32/107160_2.png) [@jughosta](https://discuss.elastic.co/u/jughosta)\
**Post date:** [October 18, 2023, 2:06pm UTC](https://discuss.elastic.co/t/scripted-url-field-of-optional-field/345245/2 "2023-10-18T14:06:13Z")

</div>

Hi @Bohdan_Dubyk! Welcome to the community!

What Kibana version are you using?

Scripted fields are deprecated. The recommended way is to create runtime fields (from Discover or Data View pages). They have similar syntax but for runtime script the final value should be wrapped with `emit(<your value>)` function instead of just `return`.

> [@Bohdan\_Dubyk](#):
>
> so that field does not exist on every document

If this field was not set for a document, please consider using the following check rather than checking for null:

```auto
if (doc["message.request_id"].size() > 0) {
...
}

```

---

<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:** [November 15, 2023, 2:06pm UTC](https://discuss.elastic.co/t/scripted-url-field-of-optional-field/345245/3 "2023-11-15T14:06:41Z")

</div>

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