Want to format date

My current date format is "2019-11-11T05:59:12.000Z" and I want to modify this with day_of_the_week. I tried to achieve it by utilising painless script but it forces me to use terms as an aggregation without mentioning date.

I need date format should be changed to this format as Mon 2019-11-11T05:59:12.000Z. I also tried painless script examples from Elasticsearch documentation but always I started and ended up with following error as "Cannot cast org.elasticsearch.script.JodaCompatibleZonedDateTime to java.time.ZonedDateTime"

I used following script copied from documentation.

ZonedDateTime input = doc['order.date'].value;
String output = input.format(DateTimeFormatter.ISO_INSTANT);

I had also tried to add two fields to construct my own format as shown below but I got an error as
image

["", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][doc['order.date'].value.dayOfWeek] + [doc['order.date'].value]

please help to achive this.

Hi @shubhamblackstratus,

You should be able to achieve it by updating field type to date and adding dddd to the format pattern:

update: for the shorter names (Mon, Tue, etc) use ddd

Regards, Dzmitry

Thank you @Dzmitry for your suggestion.

I could do this only if its related to timestamp.

I want to create scripted field by using indexed document key field named as order.date which is mapped as "date" datatype.

Please suggest.

@magnusbaeck @Dzmitry please help..!

Guys any hep over here ?

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