Write structured log but field is never recognized as 'date'

Hi!

I have a .net application which write log entries per nlog direct to Elasticsearch.
It works with strings, numbers and booleans.
Now I need to transfer a 'date' as structured log entry to Elasticsearch, but it will always just recognized as type 'keyword' doesn´t matter what format I choose.
For example:

logger.LogInformation("{mydate}",DateTime.Now.ToString("yyyy-MM-dd");

The only way it worked is when I write into elasticsearch console

PUT *myIndex*/_mapping
{
  "properties": {
    "mydate": {
      "type": "date",
      "format": "yyyy-MM-dd"
    }
  }
}

before I log the first entry from my application.
But this is not a good solution and I don´t see how I can automatically configurate this.
Any help whould be great!

I would recommend you specify the mapping through an index template. That way the mapping will be applied when the index is created.

Thanks for your reply.
I forgot to mention that we use ES 7.17.

It seems that updating runtime fields work.

PUT *myIndex*/_mapping
{
    "runtime" : {
        "mydate": {
      "type": "date"
    }
  }
}

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