# Painless - New Calculated field as a .keyword extension

**URL:** <https://discuss.elastic.co/t/painless-new-calculated-field-as-a-keyword-extension/269632>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [April 8, 2021, 5:52pm UTC](https://discuss.elastic.co/t/painless-new-calculated-field-as-a-keyword-extension/269632 "2021-04-08T17:52:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raynb](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@Raynb](https://discuss.elastic.co/u/Raynb)\
**Post date:** [April 8, 2021, 5:52pm UTC](https://discuss.elastic.co/t/painless-new-calculated-field-as-a-keyword-extension/269632/1 "2021-04-08T17:52:18Z")

</div>

In our data we have a page field with URLs and some come in as /blog/really-good-content/ and others come as /blog/really-good-content (the lack of trailing slash)

So in Painless I've made a scipted field to merge these records so I can analyze them together. This is fine. My issue is I don't know how to then use the .keyword extension, required for TSVB tables, against this new field. Even if I make calculated field just  
doc['Page.keyword'].value (none of the fancy substring stuff) I can't use it in tsvb charts.

What am I missing, how do I use Painless to make a scripted calculated field that will have a .keyword extension that I can then use in a TSVB?

Thank you

---

<div class="post-metadata">

**Author:** ![matw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matw/32/13913_2.png) [@matw](https://discuss.elastic.co/u/matw)\
**Post date:** [April 12, 2021, 10:52am UTC](https://discuss.elastic.co/t/painless-new-calculated-field-as-a-keyword-extension/269632/2 "2021-04-12T10:52:22Z")

</div>

Hi  
Scripted fields are currently not supported in TSVB, there's an issue for that in our git repository, you could use to track or comment there

> <https://github.com/elastic/kibana/issues/13928>
>
> Feature Request
> I am suggesting to include support for scripted aggregations (such as a scripted sum aggregation as described in the official...

Maybe for your use case you could use runtime fields

> **[Explore your data with runtime fields | Elasticsearch Guide \[7.12\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.12/runtime-examples.html)**

With runtime fields you can add a painless script in the mapping of you index

Best,  
Matthias

---

<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:** [May 10, 2021, 10:52am UTC](https://discuss.elastic.co/t/painless-new-calculated-field-as-a-keyword-extension/269632/3 "2021-05-10T10:52:48Z")

</div>

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