# Pie chart with extracting major from JRE version in Kibana

**URL:** <https://discuss.elastic.co/t/pie-chart-with-extracting-major-from-jre-version-in-kibana/307522>\
**Category:** Kibana\
**Created:** [June 17, 2022, 2:49pm UTC](https://discuss.elastic.co/t/pie-chart-with-extracting-major-from-jre-version-in-kibana/307522 "2022-06-17T14:49:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vmassol](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vmassol/32/17398_2.png) [@vmassol](https://discuss.elastic.co/u/vmassol)\
**Post date:** [June 17, 2022, 2:49pm UTC](https://discuss.elastic.co/t/pie-chart-with-extracting-major-from-jre-version-in-kibana/307522/1 "2022-06-17T14:49:59Z")

</div>

Hi there,

In my index I have documents with a `java.version` field representing java versions (e.g. `11.0.13`, `11.0.14.1`, etc). I'm trying to extract the major version (e.g. `11`) and display that in a pie chart in Kibana.

What's the easiest way to do this?

I started checking script fields in Kibana and to add some to my Data View but I've found that:

- it's deprecated and runtime fields are the way forward
- I couldn't use `String.split()` and [Create Scripted Field using substring before "." - #10 by aaron\_nimocks](https://discuss.elastic.co/t/create-scripted-field-using-substring-before/238096/10) doesn't seem to work either (or I don't know how to use it).

```auto
String value = doc['java.version'].value;
String[] result = /./.split(value);
return result[0];

```

Thus I wanted to check that using a runtime field is the way to go. It seems I'll need to create the runtime field in the ES mapping or in an ES search request according to [Runtime fields | Elasticsearch Guide [8.2] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/8.2/runtime.html). This seems a bit strange as I only need to create this runtime field for the purpose of viewing data in Kibana.

Could you confirm I'm going in the right direction? Seems complex-ish for my original need.

Thx!

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [June 17, 2022, 5:18pm UTC](https://discuss.elastic.co/t/pie-chart-with-extracting-major-from-jre-version-in-kibana/307522/2 "2022-06-17T17:18:18Z")

</div>

Hi @vmassol

You can add a runtime field just to the index pattern / data view  
Then it will only live in the index pattern / data view but will be available for Lens / Visualizations but will not be available in DSL queries etc..

Here is the code for the runtime field

```auto
def version = doc["java.version"].value;
if (version != null) {
    int firstDot = version.indexOf('.');
    if (firstDot > 0) {
        emit(version.substring(0, firstDot));
    return;
    }
}
emit("Unknown");

```

Go To Stack Management -\> Data Views -\> Choose Data View -\> Add Field

 ![Screen Shot 2022-06-17 at 10.11.08 AM](https://us1.discourse-cdn.com/elastic/original/3X/7/1/714a1307b7bcfae33cd867894f12275786047fe5.jpeg)

Pie Chart...

 ![Screen Shot 2022-06-17 at 10.17.56 AM](https://us1.discourse-cdn.com/elastic/original/3X/1/0/10c2426d2c106d1626c24a6fcf1ff4ee1b0acd3d.png)

---

<div class="post-metadata">

**Author:** ![vmassol](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vmassol/32/17398_2.png) [@vmassol](https://discuss.elastic.co/u/vmassol)\
**Post date:** [June 17, 2022, 5:53pm UTC](https://discuss.elastic.co/t/pie-chart-with-extracting-major-from-jre-version-in-kibana/307522/3 "2022-06-17T17:53:51Z")

</div>

This is awesome! Thanks a lot for your great answer and details 🙂

---

<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:** [July 15, 2022, 5:54pm UTC](https://discuss.elastic.co/t/pie-chart-with-extracting-major-from-jre-version-in-kibana/307522/4 "2022-07-15T17:54:18Z")

</div>

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