# New Control visualization with scripted field

**URL:** <https://discuss.elastic.co/t/new-control-visualization-with-scripted-field/196284>\
**Category:** Kibana\
**Created:** [August 22, 2019, 9:28am UTC](https://discuss.elastic.co/t/new-control-visualization-with-scripted-field/196284 "2019-08-22T09:28:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Sarkkinen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_sarkkinen/32/52799_2.png) [@Chris\_Sarkkinen](https://discuss.elastic.co/u/Chris_Sarkkinen)\
**Post date:** [August 22, 2019, 9:28am UTC](https://discuss.elastic.co/t/new-control-visualization-with-scripted-field/196284/1 "2019-08-22T09:28:39Z")

</div>

I’m currently pulling data from Pipedrive and would like to make a new control filter that would be based on string values in my data.

My index contains Deal\_title that is in the form - _CompanyName Ltd (xxxx)_ The information inside the brackets changes.

Correct me if I’m wrong, but in order to have the control visualization I’ll need to do the following:

- Create new scripted field that will add a new field in my index
- Use that Scripted field for control visualization

The problem is that I have no idea how to write this script that would take my string data and create new index value whenever it finds brackets.

---

<div class="post-metadata">

**Author:** ![nickpeihl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nickpeihl/32/112622_2.png) [@nickpeihl](https://discuss.elastic.co/u/nickpeihl)\
**Post date:** [August 22, 2019, 11:17pm UTC](https://discuss.elastic.co/t/new-control-visualization-with-scripted-field/196284/2 "2019-08-22T23:17:08Z")

</div>

Sorry, I'm not clear on the question. Can you share some example documents and what you'd expect the control options to be?

---

<div class="post-metadata">

**Author:** ![Chris\_Sarkkinen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_sarkkinen/32/52799_2.png) [@Chris\_Sarkkinen](https://discuss.elastic.co/u/Chris_Sarkkinen)\
**Post date:** [August 23, 2019, 7:26am UTC](https://discuss.elastic.co/t/new-control-visualization-with-scripted-field/196284/3 "2019-08-23T07:26:52Z")

</div>

Deal title indexing is as follows:

"Deal\_title": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}

Resulting in:  
 ![data1](https://us1.discourse-cdn.com/elastic/original/3X/6/c/6ce5e33be012899856c29fb25cf7fb1ce3872ec8.png)

I'd like to make a new control visualization that would have only the lead source that is in the brackets (maby 5-6 different sources).

 ![data2](https://us1.discourse-cdn.com/elastic/original/3X/7/f/7f250986922837b06faa668c2ea53cf6179abfee.png)

I think I'll have to make a new field from deal title data with script field and write code with painless that takes end of string and creates a new field in my index from whatever is inside of those brackets.

I'm new to painless, so I have no idea how to do this.

---

<div class="post-metadata">

**Author:** ![nickpeihl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nickpeihl/32/112622_2.png) [@nickpeihl](https://discuss.elastic.co/u/nickpeihl)\
**Post date:** [August 23, 2019, 9:01pm UTC](https://discuss.elastic.co/t/new-control-visualization-with-scripted-field/196284/4 "2019-08-23T21:01:15Z")

</div>

Thanks for clarifying. Yes, I think you'll want to use a [Painless regular expression](https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-walkthrough.html#modules-scripting-painless-regex) in a scripted field for this.

Here's a scripted field example that will extract "Bar" from "Foo (Bar)".

```auto
def m = /\((.*)\)/.matcher(doc['name'].value);
if ( m.find() ) {
   return m.group(1)
} else {
   return ''
}

```

---

<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:** [September 20, 2019, 9:01pm UTC](https://discuss.elastic.co/t/new-control-visualization-with-scripted-field/196284/5 "2019-09-20T21:01:24Z")

</div>

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