# How to use scripted fields, very basics

**URL:** https://discuss.elastic.co/t/how-to-use-scripted-fields-very-basics/100528
**Category:** Kibana
**Created:** [September 14, 2017, 12:03pm UTC](https://discuss.elastic.co/t/how-to-use-scripted-fields-very-basics/100528 "2017-09-14T12:03:31Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tomer](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@tomer](https://discuss.elastic.co/u/tomer)
#### Post date: [September 14, 2017, 12:03pm UTC](https://discuss.elastic.co/t/how-to-use-scripted-fields-very-basics/100528/1 "2017-09-14T12:03:32Z")

</div>

Hi,

I am trying to understand how to use scripted fields (the basics of it), using date field and I am unsuccessful.

I saw a lot of 'painless' code in the format as inside [this](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-script-fields.html) link, but they are all in PUT GET format and I don't know what to put inside the box of script in the Kibana what format belongs there:

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

my end result is to subtract date X by date Y.

---

<div class="post-metadata">

### Author: ![tomer](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@tomer](https://discuss.elastic.co/u/tomer)
#### Post date: [September 14, 2017, 1:00pm UTC](https://discuss.elastic.co/t/how-to-use-scripted-fields-very-basics/100528/2 "2017-09-14T13:00:19Z")

</div>

Found this and it works:

```
def dateFormat = new SimpleDateFormat("ss");
    return dateFormat.format(doc['medGotAck_MT.raw'].value - doc['MedGotMsgFromApi.raw'].value);
```

---

<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: [October 12, 2017, 1:00pm UTC](https://discuss.elastic.co/t/how-to-use-scripted-fields-very-basics/100528/3 "2017-10-12T13:00:44Z")

</div>

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