Custom date format in elasticsearch

Hi,

I am trying to index the data with the data as May 26 2022 17:41:24 . I have given the format in my index template as MMM d Y H:m:s . I have been following this link for formatting http://joda-time.sourceforge.net/api-release/org/joda/time/format/DateTimeFormat.html .

Parsing for this data is happening fine with this mentioned format. After indexing this data I have been seen in Kibana as below:

After Indexing data:
"configuration_date_time": [
"2022-01-03T17:41:24.000Z"
],
So it is coming as 3rd January but actually it is May 26.
Actual data: "configuration_date_time": "May 26 2022 17:41:24",

How come it is converting this May 26 to 3rd Jan. I am confused. Can anyone please help me on this? Where I am missing?

@roopednra...

Can you please help me on that?

DELETE discuss-time

PUT discuss-time
{
  "mappings": {
    "properties": {
      "time" : {"type": "date",
        "format": ["MMM dd yyyy HH:mm:ss"]
      }
    }
  }
}

POST discuss-time/_doc
{
  "time" : "May 26 2022 17:41:24"
}

GET discuss-time/_search
{
  "fields": [
    "*"
  ]
}

result

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "discuss-time",
        "_id" : "EQDlLIEBmlXOD4xOxm-x",
        "_score" : 1.0,
        "_source" : {
          "time" : "May 26 2022 17:41:24"
        },
        "fields" : {
          "time" : [
            "May 26 2022 17:41:24" <!---- Correct
          ]
        }
      }
    ]
  }
}
2 Likes

Thanks @stephenb .. It works.. :slight_smile: .. But I am confused why this( MMM d Y H:m:s) format give us a wrong result

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