I try to combine 2 date fields into a more meaning ful STRING scripted field based on conditions on the date to add "0" before 1 digit numbers ( May 2nd => 05-02).
This script is refused and I don't know how to solve this even after significant searches on forums
Could you please help?
I work with Elasticsearch 7.8
Thanks
if (doc['startDate'].value.getMonthValue() < 10) return ( 'Le 0'); else ('Le ') + doc['startDate'].value.getMonthValue() +
if (doc['startDate'].value.getDayOfMonth() < 10) return ( ' - 0'); else (' - ') + doc['startDate'].value.getDayOfMonth() +
if (doc['startDate'].value.getHour() < 10) return (' de 0'); else (' de ') + doc['startDate'].value.getHour() +
if (doc['endDate'].value.getHour() < 10) return ('h à 0'); else ('h à ') + doc['endDate'].value.getHour() +'h'
Hello, can you post a few examples on what you're trying to achieve? I'm trying to figure out if you can achieve this with field formatting or anything else.
thanks !
Indeed, formatting would be a solution, but I couldn't figure out how to do it,
[
{
"_id": "6148f71866c81e1752a9648aAntoine Renaud",
"endDate": "2021-09-25T22:04:00.000Z",
"startDate": "2021-09-25T22:00:00.000Z",
"shfit name with date": [
"Le 25 de 22h à 22h"
]
},
{
"_id": "6148f71866c81e1752a9648aGregory Saint Etienne",
"endDate": "2021-09-05T03:04:00.000Z",
"startDate": "2021-09-05T02:00:00.000Z",
"shfit name with date": [
"Le 5 de 2h à 3h"
]
}]
I'd like to change the second one to "Le 05 de 02h à 03h" so that I can sort these new string fields by alphabetical order. The idea is to get the start date day and hour and concatenate with the end date hour. I also need to add the month first.
This is the current code
'Le '+doc['startDate'].value.getDayOfMonth()+' de '+doc['startDate'].value.getHour()+ 'h à ' + doc['endDate'].value.getHour()+'h'
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.