Extracting MonthOfYear In Kibana Scripted Field

The following Scripted Field code is throwing an error,

def month = doc['signed_date'].date.monthOfYear;

I want to extract the months as a separate column. What am I doing wrong here?

Kindly help.

monthOfYear is not a function that is available in painless. You can access date pieces with the functions at https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-datetime.html#_datetime_pieces.

doc['timestamp'].value.getMonthValue() is an example of a scripted field that returns the month of the year from the Kibana's web logs sample data set.

2 Likes

If you want the month as a string instead of a number, you could use doc['timestamp'].value.getMonth(). That method is not listed in the docs but the docs say the datetime type is ZonedDateTime and looking at the Java docs for ZonedDateTime shows some additional getter methods not mentioned in the painless documentation.

1 Like

@Nathan_Reese Thank you soo much. :blush: Very useful doc!!

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