How to format a date as a string in Painless


(Steven Ensslen) #1

Continuing the discussion from Elasticsearch 6.2 - how to format date (epoch) field in yyyymm string in painless inline scripting:

Despite the frequent mentions of switching to java.time in the docs, my cloud.elastic.co hosted elasticsearch 6.3.0 cluster is still using Joda-Time, as is readily demonstrated by any typo: "lang": "painless", "caused_by": { "type": "illegal_argument_exception", "reason": "Unable to find dynamic method [to_String] with [1] arguments for class [org.joda.time.DateTime]."

In order to format an Elasticsearch date as a string in Painless, simply call toString(). For example doc['myDate'].value.toString('yyyyMM');


(system) #2

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