0

I have a search query for Elasticsearch which uses a groovy inline script that I need to convert to Painless language

mdt= doc.eventstartdate.value;
dtevent = new DateTime(mdt).withTime(0,0,0,0).getMillis();
d = (dtevent<dtnow?dtnow:dtevent);

As you can see, this grabs the 'eventstartdate', strips the time off (sets to 00:00:00)

Then it compares with current date (dtnow) and if less than current date, changes it to the current date (effectively there are no past dates, just today onwards)

I'm not a Java programmer and I believe the date processing has changed in Painless so looking to convert the above?

Thanks

Ben
  • 155
  • 2
  • 12

1 Answers1

0

Fixed this with:

Instant startDate = Instant.ofEpochMilli(doc.eventstartdate.date.millis);
long startDateMS = startDate.truncatedTo(ChronoUnit.DAYS).getEpochSecond() * 1000;
def d = (startDateMS<params.dtnow?params.dtnow:startDateMS);
Ben
  • 155
  • 2
  • 12