# Kibana: Trying to create a scripted field, but cannot figure out how retrieve the value of field 'client.domain'

**URL:** <https://discuss.elastic.co/t/kibana-trying-to-create-a-scripted-field-but-cannot-figure-out-how-retrieve-the-value-of-field-client-domain/378909>\
**Category:** Elasticsearch\
**Tags:** runtime-fields\
**Created:** [June 5, 2025, 11:37am UTC](https://discuss.elastic.co/t/kibana-trying-to-create-a-scripted-field-but-cannot-figure-out-how-retrieve-the-value-of-field-client-domain/378909 "2025-06-05T11:37:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jba](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jba/32/118482_2.png) [@jba](https://discuss.elastic.co/u/jba)\
**Post date:** [June 5, 2025, 11:37am UTC](https://discuss.elastic.co/t/kibana-trying-to-create-a-scripted-field-but-cannot-figure-out-how-retrieve-the-value-of-field-client-domain/378909/1 "2025-06-05T11:37:55Z")

</div>

I have an index with data from our Bitbucket servers. The documents contains a lot of fields, but the one that is of interest to me is the keyword field `client.domain` (the FQDN of Jenkins servers). I want to create a scripted field displaying a human-friendly version of the server name.

As a start, I just want to display the value of `client.domain`.

```auto
if (doc.containsKey('client.domain')) {
   String v = doc['client.domain'].value;
   emit(v);
}

```

Kibana tells me that:

> A document doesn't have a value for a field! Use doc[\<field\>].size()==0 to check if a document is missing a field!  
> Runtime fields without a script retrieve values from \_source. If the field doesn't exist in \_source, a search request returns no value.

If I emit `doc['client.domain'].size()` I get a non-zero result: 1

If I try with

```auto
String v = doc['agent.name'].value;

```

it works.

What am I doing wrong? What is it that I do not understand?

---

<div class="post-metadata">

**Author:** ![Tortoise](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tortoise/32/147587_2.png) [@Tortoise](https://discuss.elastic.co/u/Tortoise)\
**Post date:** [June 6, 2025, 5:59am UTC](https://discuss.elastic.co/t/kibana-trying-to-create-a-scripted-field-but-cannot-figure-out-how-retrieve-the-value-of-field-client-domain/378909/2 "2025-06-06T05:59:02Z")

</div>

Hello @jba

Could you please confirm if all your documents has this field?

If not you can use below logic :

```auto
 if (doc['client.domain.keyword'].size() == 0) {
            emit("Field Missing");
          } else {
            def source = doc['client.domain.keyword'].value;
            if (source == "ababababababaab") {
              emit("jenkins-dev");
            } else if (source == "bcbcbcbcbcbcbcb") {
              emit("jenkins-pre");
            } else {
              emit("Unknown");
            }
          }

```

Thanks!!

---

<div class="post-metadata">

**Author:** ![jba](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jba/32/118482_2.png) [@jba](https://discuss.elastic.co/u/jba)\
**Post date:** [June 9, 2025, 8:30pm UTC](https://discuss.elastic.co/t/kibana-trying-to-create-a-scripted-field-but-cannot-figure-out-how-retrieve-the-value-of-field-client-domain/378909/3 "2025-06-09T20:30:08Z")

</div>

I found the error. Not all documents have a value for `client.domain`. While editing the script, Kibana will show the content of a single document as a guide on the right side of the screen. Unless one has scrolled and picked a document with a non-empty `client.domain` field, the syntax checker have no way of checking the type and validity of the field. So I scrolled forward until I was at a document with the `client.domain` field, and then I could save my script.
