1

In Elasticsearch 6.2, I have an index where there are two timestamp fields as follows:

"start_ts":  { "type": "date", "format": "epoch_second"  },                       
"end_ts":    { "type": "date", "format": "epoch_second"  }  

In my painless inline script, for some calculation, I want to convert them (doc["start_ts"] and doc["end_ts"]) to this string format (yyyymm). Any idea how can it be done? I could not find any documentation for formatting in ES official documentation.

JVK
  • 3,782
  • 8
  • 43
  • 67

2 Answers2

1
doc["end_ts"].toString("yyyyMM")
Pika Supports Ukraine
  • 3,612
  • 10
  • 26
  • 42
Shoukry
  • 59
  • 2
0

If the above answer doesn't work, just add .value to it. i.e,

doc["end_ts"].value.toString("yyyyMM")
buddemat
  • 4,552
  • 14
  • 29
  • 49
  • Welcome to SO! JYou shouldn't refer to another answer as "above", since it's not sure that it will be displayed above. Instead, include the necessary information in your post. – buddemat Jul 08 '22 at 22:04