# Checking if a field exists via scripted field in Kibana 5.1

**URL:** <https://discuss.elastic.co/t/checking-if-a-field-exists-via-scripted-field-in-kibana-5-1/72945>\
**Category:** Kibana\
**Created:** [January 26, 2017, 8:00pm UTC](https://discuss.elastic.co/t/checking-if-a-field-exists-via-scripted-field-in-kibana-5-1/72945 "2017-01-26T20:00:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gkraan](https://avatars.discourse-cdn.com/v4/letter/g/6a8cbe/32.png) [@gkraan](https://discuss.elastic.co/u/gkraan)\
**Post date:** [January 26, 2017, 8:00pm UTC](https://discuss.elastic.co/t/checking-if-a-field-exists-via-scripted-field-in-kibana-5-1/72945/1 "2017-01-26T20:00:56Z")

</div>

Hi,

I am using the 'metricbeat' to pull data from several servers into a single E.S. instance, which works fine.  
I have several visualizations in Kibana based on this info, but Kibana is set to only display data not older then 15 minutes, which I did on purpose.

Now assume one of the servers running Metricbeat goes down (meaning it will not send data anymore of course), it simply means that 15 minutes later Kibana will not find data anymore for this one server, as my settings only look at data no older then 15 minutes.

The result of that is that the visualization, thus the Dashboard, show a 'No results found' message.

What I would like to do is use a scripted field (which I already use anyway) to detect if a field exists. In the case I described above, it should return a default value, but no matter what I try, it will not do this.

I know that on the Discover tab you can use _exists_:"fieldname" but that does not work in a scripted field. I have also tried to use doc[f'ieldname'].empty (which should default to 0 if it does not exist per the documentation), but that does not seem to work either.

Any suggestions ?

---

<div class="post-metadata">

**Author:** ![shaunak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shaunak/32/6643_2.png) [@shaunak](https://discuss.elastic.co/u/shaunak)\
**Post date:** [January 26, 2017, 9:51pm UTC](https://discuss.elastic.co/t/checking-if-a-field-exists-via-scripted-field-in-kibana-5-1/72945/2 "2017-01-26T21:51:40Z")

</div>

Take a look at the `?:` (aka Elvis) operator and its examples here: [https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-painless-syntax.html#painless-operators](https://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting-painless-syntax.html#painless-operators). I think that might solve your problem.

---

<div class="post-metadata">

**Author:** ![gkraan](https://avatars.discourse-cdn.com/v4/letter/g/6a8cbe/32.png) [@gkraan](https://discuss.elastic.co/u/gkraan)\
**Post date:** [January 27, 2017, 6:02pm UTC](https://discuss.elastic.co/t/checking-if-a-field-exists-via-scripted-field-in-kibana-5-1/72945/3 "2017-01-27T18:02:33Z")

</div>

That does not seem to work either. I tried a few options that way, but the result is always 'No results found', rather then the default value I try to assign.

To explain a bit more what I am doing, I have a search per system, so I can pull records from just one server at each time. If that server is down, of course at that point there will be no data at all for just that server.

Rather then showing the 'No results found' on the Dashboard, I want to be able to show a nicer message / indication, telling the user the system might be down.

So, in this case, the search does not return any data at all, which makes sense, since the server is down, thus the Beat cannot send any data to E.S. anymore.  
I suspect that this is where the problem is. If a search does not return data, it almost looks like Kibana 'defaults' to it's 'No results found' message, without taking the default I set in my script into consideration .....?

---

<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:** [February 24, 2017, 6:02pm UTC](https://discuss.elastic.co/t/checking-if-a-field-exists-via-scripted-field-in-kibana-5-1/72945/4 "2017-02-24T18:02:34Z")

</div>

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