# Return Empty URL Scripted Field if fields do not exist

**URL:** <https://discuss.elastic.co/t/return-empty-url-scripted-field-if-fields-do-not-exist/152669>\
**Category:** Kibana\
**Created:** [October 16, 2018, 1:34pm UTC](https://discuss.elastic.co/t/return-empty-url-scripted-field-if-fields-do-not-exist/152669 "2018-10-16T13:34:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![craig.wampler](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@craig.wampler](https://discuss.elastic.co/u/craig.wampler)\
**Post date:** [October 16, 2018, 1:34pm UTC](https://discuss.elastic.co/t/return-empty-url-scripted-field-if-fields-do-not-exist/152669/1 "2018-10-16T13:34:21Z")

</div>

I have a scripted field that generates a URL.

Example data:

```
{
  "field1": "foo",
  "field2": "bar",
  ... other fields ...
 }

```

Some records have values for field1/field2, others do not.

Scripted Field Info:  
URL Template: https://{{rawValue}}  
Script:

```
if ((doc['field1.keyword'].value != null) && (doc['field2.keyword'].value != null)) {
     // I pull field1/field2 out of `doc`, but for simplicity:
     return 'host/field1/field2'
} else {
    return 'url.does.not.exist.com/does/not/exist'
}

```

So currently, it generates a valid URL for documents that have field1 and field2, and generates a nonsensical URL for documents that don't have field1/field2.

So my results look like:

```
field1 | field 2 |scripted_field
--------------------------------------
a | b | https://host/a/b
         | | https://url.does.not.exist.com/does/not/exist

```

What I would like is instead of generating nonsense, being able to return something that makes it not generate a URL at all:

```
field1 | field 2 |scripted_field
--------------------------------------
a | b | https://host/a/b
         | | 

```

Any way that I can do this?

Thanks!

---

<div class="post-metadata">

**Author:** ![timroes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timroes/32/19712_2.png) [@timroes](https://discuss.elastic.co/u/timroes)\
**Post date:** [October 16, 2018, 3:22pm UTC](https://discuss.elastic.co/t/return-empty-url-scripted-field-if-fields-do-not-exist/152669/2 "2018-10-16T15:22:00Z")

</div>

Hi,

unfortunately the URL field formatter currently will always output a URL even if the field is empty. Please feel free to open an enhancement request for that on GitHub.

Usually the best value to write in case of a non existing value is just returning `null`.

Cheers,  
Tim

---

<div class="post-metadata">

**Author:** ![craig.wampler](https://avatars.discourse-cdn.com/v4/letter/c/5daacb/32.png) [@craig.wampler](https://discuss.elastic.co/u/craig.wampler)\
**Post date:** [October 16, 2018, 10:24pm UTC](https://discuss.elastic.co/t/return-empty-url-scripted-field-if-fields-do-not-exist/152669/3 "2018-10-16T22:24:33Z")

</div>

Thanks for the quick response!

---

<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 13, 2018, 10:24pm UTC](https://discuss.elastic.co/t/return-empty-url-scripted-field-if-fields-do-not-exist/152669/4 "2018-11-13T22:24:36Z")

</div>

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