# Painless Script not giving desired output

**URL:** <https://discuss.elastic.co/t/painless-script-not-giving-desired-output/301615>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [April 5, 2022, 9:48am UTC](https://discuss.elastic.co/t/painless-script-not-giving-desired-output/301615 "2022-04-05T09:48:40Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![PRASHANT\_MEHTA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/prashant_mehta/32/101764_2.png) [@PRASHANT\_MEHTA](https://discuss.elastic.co/u/PRASHANT_MEHTA)\
**Post date:** [April 5, 2022, 9:48am UTC](https://discuss.elastic.co/t/painless-script-not-giving-desired-output/301615/1 "2022-04-05T09:48:40Z")

</div>

Hello,  
I want to create an additional field in index having combined values of mount point  
and hostname.  
ex: /dev/run vxw001m001, / vas002m002 ....  
when tried to create scripted field in index patter in kibana,getting below exception,tried to work around it but unable to get output.Any suggestion would be helpful

doc['system.filesystem.mount\_point.keyword'].value + ' ' + doc['host.name'].value;

Caused by type

illegal\_state\_exception

Caused by reason

A document doesn't have a value for a field! Use doc[].size()==0 to check if a document is missing a field!

Did tried to check for null values and size,but not sure about exact query  
@spinscale can you plz help in this?

 ![mp](https://us1.discourse-cdn.com/elastic/original/3X/9/1/9134019428d1afd2007ab3f6c400569d08c323e8.png)  
 ![mp2](https://us1.discourse-cdn.com/elastic/original/3X/e/5/e5aca31877004c9eccb93ecf64187f55ea1aca28.png)  
 ![mp3](https://us1.discourse-cdn.com/elastic/original/3X/e/6/e66bdac236d8132b663c8b89860f600a82065a72.png)

---

<div class="post-metadata">

**Author:** ![Yazid\_S](https://avatars.discourse-cdn.com/v4/letter/y/7cd45c/32.png) [@Yazid\_S](https://discuss.elastic.co/u/Yazid_S)\
**Post date:** [April 5, 2022, 11:24am UTC](https://discuss.elastic.co/t/painless-script-not-giving-desired-output/301615/2 "2022-04-05T11:24:40Z")

</div>

Are you sure that this field 'system.filesystem.mount\_point.keyword' exists and has a value in every each document ?

---

<div class="post-metadata">

**Author:** ![PRASHANT\_MEHTA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/prashant_mehta/32/101764_2.png) [@PRASHANT\_MEHTA](https://discuss.elastic.co/u/PRASHANT_MEHTA)\
**Post date:** [April 5, 2022, 11:29am UTC](https://discuss.elastic.co/t/painless-script-not-giving-desired-output/301615/3 "2022-04-05T11:29:51Z")

</div>

> [@Yazid\_S](#):
>
> 'system.filesystem.mount\_point.keyword

@Yazid_S Thanks for your quick response! Yes it exists.

 ![yes](https://us1.discourse-cdn.com/elastic/original/3X/7/a/7acf6406fd123e18dc9ecc603a1f4f3c7e132308.png)

---

<div class="post-metadata">

**Author:** ![Yazid\_S](https://avatars.discourse-cdn.com/v4/letter/y/7cd45c/32.png) [@Yazid\_S](https://discuss.elastic.co/u/Yazid_S)\
**Post date:** [April 5, 2022, 11:32am UTC](https://discuss.elastic.co/t/painless-script-not-giving-desired-output/301615/4 "2022-04-05T11:32:04Z")

</div>

On your screenshot, it seems to be ' **system.filesystem.mount\_point**' not ' **system.filesystem.mount\_point.keyword**'

---

<div class="post-metadata">

**Author:** ![PRASHANT\_MEHTA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/prashant_mehta/32/101764_2.png) [@PRASHANT\_MEHTA](https://discuss.elastic.co/u/PRASHANT_MEHTA)\
**Post date:** [April 5, 2022, 11:36am UTC](https://discuss.elastic.co/t/painless-script-not-giving-desired-output/301615/5 "2022-04-05T11:36:33Z")

</div>

Mybad,you are correct its **system.filesystem.mount\_point** and it does has mising values,what is the right way to get the desired output?

 ![kk](https://us1.discourse-cdn.com/elastic/original/3X/9/d/9d4fb6056d78497123e23d32357beae69a9daed6.png)

---

<div class="post-metadata">

**Author:** ![Yazid\_S](https://avatars.discourse-cdn.com/v4/letter/y/7cd45c/32.png) [@Yazid\_S](https://discuss.elastic.co/u/Yazid_S)\
**Post date:** [April 5, 2022, 11:39am UTC](https://discuss.elastic.co/t/painless-script-not-giving-desired-output/301615/6 "2022-04-05T11:39:52Z")

</div>

You just need to add an `if` statement on ' **system.filesystem.mount\_point**' `not null`. Then you adapt your script and your output depending on if ' **system.filesystem.mount\_point**' is null or not.

---

<div class="post-metadata">

**Author:** ![PRASHANT\_MEHTA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/prashant_mehta/32/101764_2.png) [@PRASHANT\_MEHTA](https://discuss.elastic.co/u/PRASHANT_MEHTA)\
**Post date:** [April 5, 2022, 11:42am UTC](https://discuss.elastic.co/t/painless-script-not-giving-desired-output/301615/7 "2022-04-05T11:42:16Z")

</div>

Below is the image I'm trying to achive in kibana...need to dispaly only critical mount points above  
80% usage...for this I'm unable to get hostname in visual due to limited scope of elastic aggregation in kibana.The data is coming from metricbeat.

 ![desired](https://us1.discourse-cdn.com/elastic/original/3X/c/7/c75860cf5b102c2372e178f6d13a26a2205473a9.png)  
 ![aggrs](https://us1.discourse-cdn.com/elastic/original/3X/8/8/884da28d02c3609581d3ec80cf09dee0ecdac138.png)

---

<div class="post-metadata">

**Author:** ![Yazid\_S](https://avatars.discourse-cdn.com/v4/letter/y/7cd45c/32.png) [@Yazid\_S](https://discuss.elastic.co/u/Yazid_S)\
**Post date:** [April 5, 2022, 11:46am UTC](https://discuss.elastic.co/t/painless-script-not-giving-desired-output/301615/8 "2022-04-05T11:46:32Z")

</div>

You should adapt your topic. Your original question is about an error on Painless Script. Do you still have the same problem ?

---

<div class="post-metadata">

**Author:** ![PRASHANT\_MEHTA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/prashant_mehta/32/101764_2.png) [@PRASHANT\_MEHTA](https://discuss.elastic.co/u/PRASHANT_MEHTA)\
**Post date:** [April 5, 2022, 11:57am UTC](https://discuss.elastic.co/t/painless-script-not-giving-desired-output/301615/9 "2022-04-05T11:57:38Z")

</div>

I'm not sure how to make the exact script for this,still not getting the desired values.

```auto
if(doc['system.filesystem.mount_point'].value != null)
{
  return doc['system.filesystem.mount_point'].value + ' ' + doc['host.name'].value;    
}
else
{
    return "null"
}

```

 ![kkk](https://us1.discourse-cdn.com/elastic/original/3X/2/d/2d10e83d9750efe277946c08c7df02da26e42f26.png)

---

<div class="post-metadata">

**Author:** ![Yazid\_S](https://avatars.discourse-cdn.com/v4/letter/y/7cd45c/32.png) [@Yazid\_S](https://discuss.elastic.co/u/Yazid_S)\
**Post date:** [April 5, 2022, 12:03pm UTC](https://discuss.elastic.co/t/painless-script-not-giving-desired-output/301615/10 "2022-04-05T12:03:42Z")

</div>

You should also check that `doc['host.name']` is not null.  
Have you tried to replace `doc['FieldName']` by `params._source['FieldName']` ?

```auto
if(params._source['system.filesystem.mount_point'] != null && params._source['host.name'] != null)
{
  return params._source['system.filesystem.mount_point'] + ' ' + params._source['host.name'];    
}
return "null";

```

---

<div class="post-metadata">

**Author:** ![PRASHANT\_MEHTA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/prashant_mehta/32/101764_2.png) [@PRASHANT\_MEHTA](https://discuss.elastic.co/u/PRASHANT_MEHTA)\
**Post date:** [April 5, 2022, 12:22pm UTC](https://discuss.elastic.co/t/painless-script-not-giving-desired-output/301615/11 "2022-04-05T12:22:41Z")

</div>

Thanks again! Tried above script,now filed is created but all value are null.

---

<div class="post-metadata">

**Author:** ![Yazid\_S](https://avatars.discourse-cdn.com/v4/letter/y/7cd45c/32.png) [@Yazid\_S](https://discuss.elastic.co/u/Yazid_S)\
**Post date:** [April 5, 2022, 12:24pm UTC](https://discuss.elastic.co/t/painless-script-not-giving-desired-output/301615/12 "2022-04-05T12:24:31Z")

</div>

That means that both fields are never not null in the same document.

---

<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:** [May 3, 2022, 12:25pm UTC](https://discuss.elastic.co/t/painless-script-not-giving-desired-output/301615/13 "2022-05-03T12:25:24Z")

</div>

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