# Using Painless script to perform multiple actions

**URL:** https://discuss.elastic.co/t/using-painless-script-to-perform-multiple-actions/221072
**Category:** Elasticsearch
**Tags:** painless
**Created:** [February 26, 2020, 3:50pm UTC](https://discuss.elastic.co/t/using-painless-script-to-perform-multiple-actions/221072 "2020-02-26T15:50:03Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mdrowl1](https://avatars.discourse-cdn.com/v4/letter/m/977dab/32.png) [@mdrowl1](https://discuss.elastic.co/u/mdrowl1)
#### Post date: [February 26, 2020, 3:50pm UTC](https://discuss.elastic.co/t/using-painless-script-to-perform-multiple-actions/221072/1 "2020-02-26T15:50:04Z")

</div>

I am creating a visualisation in Kibana to show the average latency on traffic through the end points on a group of proxies. For the endpoints that include consumer data, I want to trim the targetUrl so I can group the traffic correctly.

I used a painless script to do this for a particular endpoint:

{  
"script": "( \_value.indexOf('account/') \> 0 ? \_value.substring(0, \_value.indexOf('/account/')+9) : \_value)"  
}

The script looks for /account/ in the targetUrl field, and trims anything that comes after it - this traffic can then be grouped and I can get the average latency.

The problem I am having is that there are several endpoints like this in the data so I need my script to perform multiple trims. Can I add to my script so it will do this? I imagine it would look something like:

{  
"script": "( \_value.indexOf('account/') \> 0 ? \_value.substring(0, \_value.indexOf('/account/')+9) : \_value);  
(\_value.indexOf('account-details') \> 0 ? \_value.substring(0, \_value.indexOf('/account-details')+16) : \_value)"  
}

I am assuming something like this is possible, but I can't figure out the syntax to get it to work.

---

<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: [March 25, 2020, 3:50pm UTC](https://discuss.elastic.co/t/using-painless-script-to-perform-multiple-actions/221072/2 "2020-03-25T15:50:13Z")

</div>

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