Using Painless script to perform multiple actions

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.

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