Runtime field script error: Cannot cast from [java.lang.String] to [void] in Kibana 8.17

Hi everyone, I'm working with Kibana 8.17 and trying to create a runtime field using a Painless script to tag http.request.referrer into sectors based on domains.

I followed the docs here:

Goal:

Create a runtime field named referrer_sector, of type keyword, that:

  • Returns "sector_a" if the referrer contains mywebsite.com
  • Returns "other" otherwise
  • Returns "unknown" if the field is missing or empty

Script I used:

if (doc.containsKey('http.request.referrer') && !doc['http.request.referrer'].empty) {
  String ref = doc['http.request.referrer'].value.toLowerCase();

  if (ref.contains("mywebsite.com")) {
    return "sector_a";
  } else {
    return "other";
  }
} else {
  return "unknown";
}

Field Settings:

  • Name: referrer_sector
  • Type: keyword
  • “Set value” is enabled

Problem:

I keep getting the following error:

Cannot cast from [java.lang.String] to [void]. Verify that you have correctly set the runtime field type.

Even though:

  • I'm returning a string
  • Type is explicitly set to keyword
  • The field http.request.referrer exists and is visible in Discover

I even tried using .keyword subfield and checking .size() — same error.

Error Screenshot:

  • Is this a bug?
  • Or is there something subtle I'm missing in setting up the script?

Any help is greatly appreciated!Thankyouu so much!

Hello @Hendrawns

I did check & see similar error message :

As per the documentation try using emit instead of return

Thanks!!

1 Like

Ahhhh iseee, woah thankyouu so much for helping me :laughing: