Setting timezone for JSON Input


#1

The following script works as a JSON Input
{
"script": {
"inline": "Calendar today = Calendar.getInstance(); long end = today.getTimeInMillis(); Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.clear(Calendar.MINUTE); cal.clear(Calendar.SECOND); cal.clear(Calendar.MILLISECOND); long start = cal.getTimeInMillis(); if (doc['i.Transaction Date'].date.getMillis()>= start) { return doc['i.Sales'].value; } return 0;",
"lang": "painless"
}
}

But once I add timezone:
{
"script": {
"inline": "TimeZone timeZone = TimeZone.getTimeZone("UTC"); Calendar today = Calendar.getInstance(timeZone); long end = today.getTimeInMillis(); Calendar cal = Calendar.getInstance(timeZone); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.clear(Calendar.MINUTE); cal.clear(Calendar.SECOND); cal.clear(Calendar.MILLISECOND); long start = cal.getTimeInMillis(); if (doc['i.Transaction Date'].date.getMillis() <= end && doc['i.Transaction Date'].date.getMillis()>= start) { return doc['i.Sales'].value; } return 0;",
"lang": "painless"
}
}
It doesn't run.

However, both scripts execute as Scripted Fields.

Any ideas?


(system) #2

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