# Scripted field in kibana

**URL:** <https://discuss.elastic.co/t/scripted-field-in-kibana/269465>\
**Category:** Elasticsearch\
**Created:** [April 7, 2021, 12:50pm UTC](https://discuss.elastic.co/t/scripted-field-in-kibana/269465 "2021-04-07T12:50:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Changra](https://avatars.discourse-cdn.com/v4/letter/c/f1d935/32.png) [@Changra](https://discuss.elastic.co/u/Changra)\
**Post date:** [April 7, 2021, 12:50pm UTC](https://discuss.elastic.co/t/scripted-field-in-kibana/269465/1 "2021-04-07T12:50:57Z")

</div>

Hi Team,

I have been to substract the date value and store the value in the variable defined as " duration" and then check if the value is smaller than 2 then return a value through scripted filed in kibana

` ``  
if (doc['request\_time'].size()!=0 && doc['response\_time']!=0 && doc['response\_time'].value.getMillis() \> doc['request\_time'].value.getMillis())  
{  
return doc['response\_time\_milli'].value.getMillis() - doc['request\_time\_milli'].value.getMillis()= doc['duration'].value.getMillis();  
}  
if (doc['duration'].value.getMillis() \< 2)  
{  
return doc['duration\_2'].value.getMillis() = 1;  
}  
```

`although i get an error`

````
"script": "if (doc['request_time'].size()!=0 && doc['response_time']!=0 && doc['response_time'].value.getMillis() > doc['request_time'].value.getMillis())\n {\n return doc['response_time_milli'].value.getMillis() - doc['request_time_milli'].value.getMillis()= doc['duration'].value.getMillis();\n }\n if (doc['duration'].value.getMillis() < 2)\n {\n return doc['duration_2'].value.getMillis() = 1;\n }\n ",
"lang": "painless",
"caused_by": {
 "type": "illegal_argument_exception",
 "reason": "Left-hand side cannot be assigned a value."
}
```

Regards,

````

Neha Changra

---

<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:** [May 5, 2021, 12:51pm UTC](https://discuss.elastic.co/t/scripted-field-in-kibana/269465/2 "2021-05-05T12:51:31Z")

</div>

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