# Access Kibana config value from scripted field?

**URL:** <https://discuss.elastic.co/t/access-kibana-config-value-from-scripted-field/122393>\
**Category:** Kibana\
**Created:** [March 4, 2018, 3:33am UTC](https://discuss.elastic.co/t/access-kibana-config-value-from-scripted-field/122393 "2018-03-04T03:33:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dcode](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dcode/32/28390_2.png) [@dcode](https://discuss.elastic.co/u/dcode)\
**Post date:** [March 4, 2018, 3:33am UTC](https://discuss.elastic.co/t/access-kibana-config-value-from-scripted-field/122393/1 "2018-03-04T03:33:41Z")

</div>

I'm interested in programmatically creating a scripted field using Painless. Namely, I want to create a string type that is formatted as a URL. I can create the field without problem. I can also push the Kibana configuration via the create index-pattern API. However, I'd like to be able to template out the base URL into a Kibana config value. This way a user can just change the config value (or via a script) for their environment and not have to change the Painless script.

The only other option that I can think of is to template the index pattern on disk, render the template, and update the index pattern.

Thanks!

---

<div class="post-metadata">

**Author:** ![jbudz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jbudz/32/45922_2.png) [@jbudz](https://discuss.elastic.co/u/jbudz)\
**Post date:** [March 4, 2018, 7:13pm UTC](https://discuss.elastic.co/t/access-kibana-config-value-from-scripted-field/122393/2 "2018-03-04T19:13:28Z")

</div>

You can use the url field formatter on top of a scripted field, is that sufficient? It takes a template:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/5/f5413194d68aa22a898ab8cb1f2420a0b9ebe3a8.png)

From a painless script there's no way to access Kibana variables currently. The script is executed on elasticsearch and we aren't adding extras.

---

<div class="post-metadata">

**Author:** ![dcode](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dcode/32/28390_2.png) [@dcode](https://discuss.elastic.co/u/dcode)\
**Post date:** [March 5, 2018, 4:44pm UTC](https://discuss.elastic.co/t/access-kibana-config-value-from-scripted-field/122393/3 "2018-03-05T16:44:04Z")

</div>

I tried that, and it would be great, except the value field of the template escapes slashes needed for my URI build.

Right now I've got:

```auto
String baseUrl = 'https://192.168.1.2:8443/api/uri/';
if (doc['@meta.event_type'].value == 'network')
{ 
  String host1 = doc['@meta.orig_host'].value;
  String host2 = doc['@meta.resp_host'].value;
  String port1 = doc['@meta.orig_port'].value.toString();
  String port2 = doc['@meta.resp_port'].value.toString();
  String timestamp = doc['@timestamp'].getDate().toString();
  timestamp = timestamp.substring(0,timestamp.indexOf('Z'));
  String begin = timestamp.substring(0,timestamp.indexOf('.')) + 'Z';
  
  return baseUrl + 
              'host/' + host1 + '/port/' + port1 +
             '/host/' + host2 + '/port/' + port2 + 
             '/after/' + begin + '/';
}
return null;

```

The baseUrl is configurable at install time. So what I'll need to do is run a Jinja2 engine or something on the `index-pattern` json file before uploading it via the API. It'd be super helpful to expose the parameter feature of Painless scripts in Kibana. I'm concerned how well a template engine will do on a JSON file with a quoted JSON string embedded, that contains template escapes `{{ }}`

---

<div class="post-metadata">

**Author:** ![jbudz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jbudz/32/45922_2.png) [@jbudz](https://discuss.elastic.co/u/jbudz)\
**Post date:** [March 7, 2018, 9:42pm UTC](https://discuss.elastic.co/t/access-kibana-config-value-from-scripted-field/122393/4 "2018-03-07T21:42:23Z")

</div>

Got you, and agreed. As a workaround does the current scripted field you have with the slashes and then using the url formatter on top work?

---

<div class="post-metadata">

**Author:** ![dcode](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dcode/32/28390_2.png) [@dcode](https://discuss.elastic.co/u/dcode)\
**Post date:** [March 8, 2018, 12:03am UTC](https://discuss.elastic.co/t/access-kibana-config-value-from-scripted-field/122393/5 "2018-03-08T00:03:20Z")

</div>

No, I'm sorry but it doesn't because the value is URL encoded when passed into the URL template. I mean, sanitizing input is important, but it just doesn't work for the URL use case when you're trying to build a URI. As a workaround, I'll just template the index pattern offline and update when necessary.

If I want to make a feature requires for parameter support, do I do that via GitHub issues for kibana?

---

<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:** [April 5, 2018, 12:03am UTC](https://discuss.elastic.co/t/access-kibana-config-value-from-scripted-field/122393/6 "2018-04-05T00:03:55Z")

</div>

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