3

Elastic Search Painless scripts returns a warning that a date format using date.toString('HH') will be Deprecated.

Following warning:

! Deprecation: 299 Elasticsearch-6.7.0-8453f77 "Use of the joda time method [toString(String)] is deprecated. Use [a DateTimeFormatter] instead."

But when I try to use the Java DateTimeFormatter to format date, I get JodaCompatibleZonedDateTime format not found.

What am I missing here?

getHour() works, but it is not in the correct format. doc[params.date_field].date.format(f); Not working. doc[params.date_field].value.toString('HH'); Is deprecated.


 "aggs": {
    "byHour": {
      "terms": {
        "script": {
          "lang": "painless",
          "source": """
            DateTimeFormatter f = DateTimeFormatter.ofPattern(params.format); 
            return  doc[params.date_field].value.format(f);
          
          """,
          "params": {
            "date_field": "receivedTime",
            "format": "HH"
          }
        },
        "size": 24,
        "order": {
          "_key": "asc"
        }
      }
    }
  }

Error: dynamic method [org.elasticsearch.script.JodaCompatibleZonedDateTime, format/1] not found

Community
  • 1
  • 1
  • Hi @Dawid, I am also facing this problem. Did you solve this – Richa Jun 14 '19 at 14:25
  • No, but I believe that that datetime formatter that I use is just not supporten in the version of elastic I use. But I have not been able to try another version. And not on that project anymore. – Dawid Parvulescu Jun 14 '19 at 14:39
  • actual the one you are using is joda date time function. For java 8 you have to use it like this.`DateTimeFormatter.ofPattern(params.format).format(doc[params.field].value)`. Though it is also not working. as argument of `format` method should be TemporalAccessor – Richa Jun 14 '19 at 14:43
  • Joda => toString("your date format"). The other one is from the java 8 docs...https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html – Dawid Parvulescu Jun 14 '19 at 15:01

0 Answers0