# Create new field "Year" from a complete date

**URL:** https://discuss.elastic.co/t/create-new-field-year-from-a-complete-date/281332
**Category:** Kibana
**Created:** [August 13, 2021, 10:06am UTC](https://discuss.elastic.co/t/create-new-field-year-from-a-complete-date/281332 "2021-08-13T10:06:03Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Raptoresse](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raptoresse/32/92968_2.png) [@Raptoresse](https://discuss.elastic.co/u/Raptoresse)
#### Post date: [August 13, 2021, 10:06am UTC](https://discuss.elastic.co/t/create-new-field-year-from-a-complete-date/281332/1 "2021-08-13T10:06:03Z")

</div>

Hi everybody !

I have a probleme : I have a field "date". I want to select juste the year, and create a vizualisation "controls" type (Add dropdown menus and range sliders to your dashboard) with the new field.

For this i create a scripted field :

```auto

doc['participations.date'].value.year

```

It works, but when i insert the new field in vizualisation type "controls" I have an error : "Unable to fetch terms, error : Eserror".

Do you have an idea what is wrong please ?

Thank you very much for your help !

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [August 15, 2021, 5:20pm UTC](https://discuss.elastic.co/t/create-new-field-year-from-a-complete-date/281332/2 "2021-08-15T17:20:37Z")

</div>

Hi @Raptoresse Welcome to the community.

I suspect the problem is, is that scripted fields are not available for every control / visualization etc.

There is a new field type Runtime Fields (similar to scripted but much better) that are available like any other field

Perhaps take a look

> **[Discover | Kibana Guide \[7.14\] | Elastic](https://www.elastic.co/guide/en/kibana/current/discover.html#add-field-in-discover)**

> **[Runtime fields | Elasticsearch Guide \[7.14\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.14/runtime.html)**

---

<div class="post-metadata">

### Author: ![Raptoresse](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raptoresse/32/92968_2.png) [@Raptoresse](https://discuss.elastic.co/u/Raptoresse)
#### Post date: [August 16, 2021, 9:33am UTC](https://discuss.elastic.co/t/create-new-field-year-from-a-complete-date/281332/3 "2021-08-16T09:33:01Z")

</div>

Thanks Stephenb !

Your proposal run on the latest version of kibana, but I'm on 7.11 and I can't change for the moment 😕

Why that scripted field is not available for control ? Because it's a date type ? I tried to change for a string and take juste the four latest caracteres but it also don't works...

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [August 16, 2021, 3:13pm UTC](https://discuss.elastic.co/t/create-new-field-year-from-a-complete-date/281332/4 "2021-08-16T15:13:29Z")

</div>

Yes sorry as I read closer the drop down control needs a type `keyword` not date or text

In the script

`"type": "keyword"`

---

<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: [September 13, 2021, 3:14pm UTC](https://discuss.elastic.co/t/create-new-field-year-from-a-complete-date/281332/5 "2021-09-13T15:14:12Z")

</div>

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