Need script to convert ISO field to Mill format

Hi Team,

  We had stored one date field in ISO format (2019-06-25) but now want to convert it into Millisecond format (1561420800000), we don't have hour, min & sec information stored in the date field. We can take default (2019-06-25 00:00:00) to convert it into millisecond format.

 Can you guys help us here to write a script which can convert all the data we have in our cluster in Millisecond format.

Stored Date field: 2019-06-25
Desired Date Field: 1561420800000

 Thanks in advanced.

Regards!
Deepak Bhatt

you can use a script processor for this

POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "processors": [
      {
        "script": {
          "lang": "painless",
          "source": "ctx.epoch = LocalDate.parse(ctx.date).atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli()"
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "date": "2019-06-30"
      }
    }
  ]
}

See the ingest node docs for more information

1 Like

Thanks Alexander, I have tried this on my local and is working fine will try with actual data and let you know the output. Thanks for your help.... :slight_smile:

1 Like

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