Visualization: Controls with map properties

Hello,
I want to create option lists controls for a filtering visualization. My data model looks something similar like this:

    {
      "id": "id",
      "name": "name",
      "properties": [
        "key=value",
        "key2=value2",
      ]
    }

I want to create an option list with only "properties.key2"-values. So, the option list should look like "['value2']". But I can only create something like "['key=value', 'key2=value2']". How can I pre filter my control? And how can I specify a prefix for shown options like "key2=.*" and replace the "key2=" in all options in my list?

My Kibana version is 7.9.2.

Greetings!

It sounds like a scripted field (https://www.elastic.co/guide/en/kibana/current/scripted-fields.html) would be a good use case for this. Create a new scripted field "key2Property" which looks up values starting with key2 from the properties array and use that to filter instead.

Thanks for your reply.

This sounds exactly like what I need.

My properties are saved as text, so I have to split by , to convert it to a list for iterating. But how I can do it?

My script:

def propertiesAsString = doc["properties"].value;
String returnValue;

for (value in propertiesAsString.split(","))
{
    if (value.startsWith("key="))
    {
        returnValue = value.replace("key=", ""); 
    }
}

return returnValue;

Following errors are displayed:

Caused by type
illegal_argument_exception
Caused by reason
dynamic method [java.lang.String, split/1] not found

Greetings!

Hey,String#split is not whitelisted in Painless by default because it can be potentially expensive to compute.

Pattern p = /,/

// ...

p.split(propertiesAsString)

// ...

Should do the trick.

Hey,

thanks for the reply.

It seems to be right, but now I get another error:

[script] Too many dynamic script compilations within, max: [75/5m]; please use indexed, or scripts with parameters instead; this limit can be changed by the [script.context.field.max_compilations_rate] setting

Is this because I have to configure my Kibana for pattern usages? Or how can I handle this error?

Greetings!

Can you copy/paste your complete script?

Here is my script:

def propertiesAsString = doc["properties"].value;
String returnValue;
Pattern pattern = /,/;

for (value in pattern.split(propertiesAsString))
{
    if (value.startsWith("key="))
    {
        returnValue = value.replace("key=", ""); 
    }
}

return returnValue;

Greetings!

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