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

**URL:** https://discuss.elastic.co/t/write-structured-log-but-field-is-never-recognized-as-date/348920
**Category:** Elasticsearch
**Created:** [December 8, 2023, 3:46pm UTC](https://discuss.elastic.co/t/write-structured-log-but-field-is-never-recognized-as-date/348920 "2023-12-08T15:46:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Heija](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/heija/32/129578_2.png) [@Heija](https://discuss.elastic.co/u/Heija)
#### Post date: [December 8, 2023, 3:46pm UTC](https://discuss.elastic.co/t/write-structured-log-but-field-is-never-recognized-as-date/348920/1 "2023-12-08T15:46:21Z")

</div>

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:

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

```

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

```auto
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!

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [December 8, 2023, 3:48pm UTC](https://discuss.elastic.co/t/write-structured-log-but-field-is-never-recognized-as-date/348920/2 "2023-12-08T15:48:55Z")

</div>

I would recommend you specify the mapping through an [index template](https://www.elastic.co/guide/en/elasticsearch/reference/8.11/index-templates.html). That way the mapping will be applied when the index is created.

---

<div class="post-metadata">

### Author: ![Heija](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/heija/32/129578_2.png) [@Heija](https://discuss.elastic.co/u/Heija)
#### Post date: [December 11, 2023, 12:01pm UTC](https://discuss.elastic.co/t/write-structured-log-but-field-is-never-recognized-as-date/348920/3 "2023-12-11T12:01:29Z")

</div>

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

It seems that [updating runtime fields](https://www.elastic.co/guide/en/elasticsearch/reference/7.17/runtime-mapping-fields.html#runtime-updating-scripts) work.

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

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [January 8, 2024, 12:01pm UTC](https://discuss.elastic.co/t/write-structured-log-but-field-is-never-recognized-as-date/348920/4 "2024-01-08T12:01:53Z")

</div>

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