# Hide painless script calculation in certain conditions

**URL:** <https://forum.opensearch.org/t/hide-painless-script-calculation-in-certain-conditions/16673>\
**Category:** OpenSearch\
**Created:** [November 15, 2023, 9:26am UTC](https://forum.opensearch.org/t/hide-painless-script-calculation-in-certain-conditions/16673 "2023-11-15T09:26:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![linkimos](https://avatars.discourse-cdn.com/v4/letter/l/a4c791/32.png) [@linkimos](https://forum.opensearch.org/u/linkimos)\
**Post date:** [November 15, 2023, 9:26am UTC](https://forum.opensearch.org/t/hide-painless-script-calculation-in-certain-conditions/16673/1 "2023-11-15T09:26:41Z")

</div>

**Describe the issue** :  
I have created a Painless script to extract data from specific log messages. The script is intended to apply only to logs containing certain messages. However, currently, it’s applying to all logs, assigning a default value (`0` ) when the relevant message is not found. I also tried to change the returned value to ‘false’ and ‘null’, but it still showed the field name without any value.  
I want to know how can I hide the painless script calculated field in conditions where there is no data at all.  
The script is attached below.

**Configuration** :

if (doc[‘msg.keyword’].size() != 0 && doc[‘msg.keyword’].value.equals(‘starts processing request headers’)) {  
return 1;  
} else {  
return false;  
}

**Relevant Logs or Screenshots** :

 ![image](https://us1.discourse-cdn.com/flex019/uploads/mauve_hedgehog/original/2X/7/79aaf7d96ef0eee59ed0296e63ff605df263ec8a.png)

---

<div class="post-metadata">

**Author:** ![Mantas](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Mantas](https://forum.opensearch.org/u/Mantas)\
**Post date:** [November 15, 2023, 3:23pm UTC](https://forum.opensearch.org/t/hide-painless-script-calculation-in-certain-conditions/16673/2 "2023-11-15T15:23:34Z")

</div>

Hi @linkimos ,

You could try something like this:

```auto
POST [index]/_update_by_query
{
  "script": {
    "lang": "painless",
    "source": "ctx._source.[FieldName] = 1"
  },
  "query": {
    "match": {
      "msg.keyword": "starts processing request headers"}
    
  }
}

```

Best,  
Mantas

---

<div class="post-metadata">

**Author:** ![linkimos](https://avatars.discourse-cdn.com/v4/letter/l/a4c791/32.png) [@linkimos](https://forum.opensearch.org/u/linkimos)\
**Post date:** [November 15, 2023, 7:16pm UTC](https://forum.opensearch.org/t/hide-painless-script-calculation-in-certain-conditions/16673/3 "2023-11-15T19:16:12Z")

</div>

Hi, thanks for your reply.  
Unfortunately, although I am getting 200, it doesn’t work.  
Any idea?

---

<div class="post-metadata">

**Author:** ![Mantas](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Mantas](https://forum.opensearch.org/u/Mantas)\
**Post date:** [November 17, 2023, 11:32am UTC](https://forum.opensearch.org/t/hide-painless-script-calculation-in-certain-conditions/16673/4 "2023-11-17T11:32:17Z")

</div>

Hi @linkimos ,

The 200 indicates that your update was successful.

Best,  
Mantas
