Bad Request when using scripted field in a table

Hey,
Creating a table visualisation with a scripted field.
When I add the field parent_name.keyword , Scripted, the table showing OK.
When I remove the field parent_name.keyword, I get the error below.
Could not find errors in logs (Kibana/Elastic), or maybe looking in the wrong place?
image
This is my script

def ans = "N/A";
if(doc['rel_type.keyword'].size()==0)
{
    return ans;
}
else
{
    def str = doc['rel_type.keyword'].value;
    def len = str.length();
    def i = str.lastIndexOf(':');
        if(i != -1)
        {
            ans = str.substring(i+1,len);
        }
        else
        {
            return ans;
        }
    return '[' + ans+ '] ' + doc['parent_name.keyword'].value;
}

Bottom line,
The scripted field is made of a concatenation of a field, and it is required that the original field, that is concatenated in the script, will be part of the table?
Any thoughts?

Thanks

Hey @AClerk. I can't reproduce it. I have created a simpler scripted field which is a result of concatenation of two others

def category = doc['category.keyword'].value;
def name = doc['customer_first_name.keyword'].value;
return '[' + category+ '] ' + name;

and I can create a table visualization with terms only with the scripted field present


Maybe I am missing some info here. Which version of kibana do you use? Moreover have you checked the results of this field on the preview? It is located at the bottom of the scripted field creation form:

Does it seem fine? Moreover what kind of fields are the rel_type and parent_name?

Hi @Stratoula_Kalafateli
Thanks for the reply.
The version used is 7.9.1
The filed looks great in the preview.
The fields are of type 'text'.
It is weird behaviour, never saw this before.

Cheers!