# @timestamp formatting month to month name

**URL:** <https://discuss.elastic.co/t/timestamp-formatting-month-to-month-name/224422>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [March 20, 2020, 1:14pm UTC](https://discuss.elastic.co/t/timestamp-formatting-month-to-month-name/224422 "2020-03-20T13:14:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeterHeming](https://avatars.discourse-cdn.com/v4/letter/p/35a633/32.png) [@PeterHeming](https://discuss.elastic.co/u/PeterHeming)\
**Post date:** [March 20, 2020, 1:14pm UTC](https://discuss.elastic.co/t/timestamp-formatting-month-to-month-name/224422/1 "2020-03-20T13:14:54Z")

</div>

Hey fellas,

I was looking around and came across 'scripted fields', the painless feature is great and also supports native Java methods. I just have a couple of question.

The documentation says: [https://www.elastic.co/guide/en/elasticsearch/reference/7.x/modules-scripting-expression.html#\_date\_field\_api](https://www.elastic.co/guide/en/elasticsearch/reference/7.x/modules-scripting-expression.html#_date_field_api)

example

`date['@timestamp'].date.monthOfYear`

but on my installation, I can only access it with

`date['@timestamp'].value.monthOfYear`

First question: Why does it say here value and not date, even though the data format is 'date'

I would like to display on my x-axis the day of the month next to the month name  
example

`12 Feb" or "12. Feb`

because right now my x-axis is formatted as "YYYY-MM-DD"  
I know I can change it in **Management =\> Advanced Settings =\> dateFormat:scaled**  
but this setting applies globally and since I just want to have specific visualization displayed with the month name, I would like to take the 'scripted field' solution

My code for the scripted field is:

```auto
def month = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September','October', 'November', 'December']; 
return (doc["@timestamp"].value.monthOfYear+". "+month[(doc["@timestamp"].value.monthOfYear)-1])

```

Output is: 12. February

As you can see, Im concatenating the values which is the result of a return type of "String".  
So trying to use this scripted field for the visualization for the x-axis results into Unexepected data type.

Second Question: Does someone have a solution for this?

I looked around in the native Java library but the documentation of Elastic does not really show how to call/invoke the functions within the painless/scripted field environment.

Third Question: How can I invoke the native Java methods within the scipted field env? Im using the Kibana UI on the Management as an Editor and there is no Code Completion, so its hard to try out the things on your own

---

<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 17, 2020, 1:22pm UTC](https://discuss.elastic.co/t/timestamp-formatting-month-to-month-name/224422/2 "2020-04-17T13:22:15Z")

</div>

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