Painless is not that painless

Hi

I am a simple thing, like assigning a text to a string variable, and then just return the value. But I keep getting compile error:

if (!doc.containsKey("url.query") || doc["url.query"].empty) {
   return null;
}

String params = "hej";

return params;

The compiler error is with the String type? What am i doing wrong. I think the painless very often, can painfull instead.

/Casper

Where are you doing this script?
What is the mapping of the field you are trying to run a script against?

I am assuming you are doing a script against a field that isn't a String.

I was creating a scripted field in Kibana. I solved the problem by changing the variable name from params to tmp??? I didn't know params is reserved word.

1 Like

I know it's reserved in Painless Lab but wouldn't think it carries over from that. Guess it's also used in templates and queries, passing in params.

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

@Casper_Thrane, we recently updated our documentation for how to write scripts. Hopefully this information helps, but if not, please let us know where we can improve!

Also, consider using runtime fields instead of Kibana scripted fields. They're more flexible, and you don't need to index them.