How to convert String "date+time+tz" to timestamp

Hello every one,
I want to replace 3 fields that contains string(date) , string(time) and string(tz) by a new field with date type that contains (date+time+tz) converted.

{  
 "query":{  
 "bool":{  
     "must_not":{  
        "exists":{  
           "field":"new_date"
        }
     }
  }
},
"script":{  
  "inline":"ctx._source.new_date = ctx._source.date +  ctx._source.time + ctx._source.tz",
  "lang":"groovy"
}
}

When i apply this , i got :

{
"error": {
"root_cause": [
  {
    "type": "script_exception",
    "reason": "error evaluating ctx._source.new_date = ctx._source.date + ctx._source.time + ctx._source.tz",
    "script_stack": [],
    "script": "",
    "lang": "groovy"
  }
],
"type": "script_exception",
"reason": "error evaluating ctx._source.new_date = ctx._source.date + ctx._source.time + ctx._source.tz",
"caused_by": {
  "type": "null_pointer_exception",
  "reason": "Cannot execute null+null"
},
"script_stack": [],
"script": "",
"lang": "groovy"
},
"status": 500
}

This is the string one , Now how can i convert This to timestamp

Thank you for your help

So... you have an elasticsearch input in your Logstash configuration?

If yes, the general answer is to use a date filter on the new_date field. I can't be more specific than that without further details on what the date, time, and tz fields look like.

Thank you for your reply,
This is what i have :

GET myindex/_search
{
  "query": {
  "match_all": {}
  }
}


"hit": {
"total": 148563278,
"max_score": 1,
"hit": [
  {
    "_index": "myindex",
    "_type": "mytype",
    "_id": "1",
    "_score": 1,
    "_source": {
      "date": "2016-06-30",
      "tz": "UTC",
      "time": "10:21:16",

I want to :
add 2 other fields:

  • field1 = date_time_tz_str ( string : concatenation of 3 fields )
  • field2 = date_time_tz ( timestamp ) conversion of field ( date_time_tz_str)

Use a mutate filter to concatenate the field values, then use a date filter to parse field1 into field2.

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