Scripted field cannot cast from String to Double

I'm trying to do some scripting on a field we have... when I preview the results it works fine, but when I go to "Discover" I get the following error: [class_cast_exception] class_cast_exception: Cannot cast from [java.lang.String] to [double].
Note: my scripted field is named org_name.

def substr = '';
def index = 0;
def url = doc['url.full'].value;
index = url.indexOf(".");
while(index != -1) {
        substr = url.substring(url.indexOf(".")+1);
        if(substr.indexOf(".") != -1){
            url = substr;
            index = substr.indexOf(".");
        } else {
            return url.substring(0, index);
        }
    }
} else {
    return "";
}

The goal of this script is to take something like https://www.google.com and turn it into google without the use of regex. The "preview results" shows me the following:

  "_id": "{my doc ID goes here}",
  "org_name": [
   "robinhood"
  ]
 }

but when I go into the Discover tab I get the error above.

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