To convert the Integers into a String

I have collected the metrics from a device through snmp input plugin and the field value is 0 & 1. How can I convert these values into strings (like 0 as Open, 1 as Close) in Kibana dashboards.

Hi @Maruthappan_Muthu

What version are you on?

There are a number of ways to do this but if you just want to see this in Kibana Visualizations and dashboards the easiest way is to add a runtime field to the the Index Pattern / Data View
(you could add it to the actual mapping at some point if you want) Read on runtime fields

Go To Stack Management -> Index / Pattern or Data View depending on the version

Add Field

Here is the sample code...replace with your field names etc...

def status = doc['snmp_status'].value;
if (status != null ) {
    if (status == 1 ) {
        emit ("open");
    else {
        emit ("closed");

Discover ... and it will work in other Visulazations like Lens etc.

1 Like

Hello @stephenb , This is awesome! I will check this and get back to you. Thanks!
Btw, I am using the version of Elasticsearch 8.3.2

1 Like

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