# Bad Request when using scripted field in a table

**URL:** <https://discuss.elastic.co/t/bad-request-when-using-scripted-field-in-a-table/266615>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [March 8, 2021, 10:48pm UTC](https://discuss.elastic.co/t/bad-request-when-using-scripted-field-in-a-table/266615 "2021-03-08T22:48:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [March 8, 2021, 10:48pm UTC](https://discuss.elastic.co/t/bad-request-when-using-scripted-field-in-a-table/266615/1 "2021-03-08T22:48:10Z")

</div>

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](https://us1.discourse-cdn.com/elastic/original/3X/4/b/4b21a851a8622e95e2089687dca73f32e2109215.png)  
This is my script

```auto
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

---

<div class="post-metadata">

**Author:** ![Stratoula\_Kalafateli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stratoula_kalafateli/32/70923_2.png) [@Stratoula\_Kalafateli](https://discuss.elastic.co/u/Stratoula_Kalafateli)\
**Post date:** [March 22, 2021, 10:48am UTC](https://discuss.elastic.co/t/bad-request-when-using-scripted-field-in-a-table/266615/2 "2021-03-22T10:48:51Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/1/91c34657fe789f76347656fbcc26ae8e0a778a87.png)  
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:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/c/ac5e41cf11f90e9bc6257e2a3cd8b38d4164ead2.png)

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

---

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [March 23, 2021, 12:00am UTC](https://discuss.elastic.co/t/bad-request-when-using-scripted-field-in-a-table/266615/3 "2021-03-23T00:00:51Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 20, 2021, 12:01am UTC](https://discuss.elastic.co/t/bad-request-when-using-scripted-field-in-a-table/266615/4 "2021-04-20T00:01:03Z")

</div>

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