# Problem with JSON date types

**URL:** https://discuss.elastic.co/t/problem-with-json-date-types/194780
**Category:** Beats
**Created:** [August 12, 2019, 3:35am UTC](https://discuss.elastic.co/t/problem-with-json-date-types/194780 "2019-08-12T03:35:40Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ajhstn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ajhstn/32/24629_2.png) [@ajhstn](https://discuss.elastic.co/u/ajhstn)
#### Post date: [August 12, 2019, 3:35am UTC](https://discuss.elastic.co/t/problem-with-json-date-types/194780/1 "2019-08-12T03:35:40Z")

</div>

I am generating custom logs formatted as single line JSON with Date fields and sending them to ES with Filebeat, however when the index and pattern is created, the date fields are Strings and numbers instead of Dates.

datetest.ps1

```
@{ Date = (Get-Date) } | ConvertTo-Json -Compress | Out-File -Encoding utf8 -Force -Append file.json
@{ ToFileTimeUtc = (Get-Date).ToFileTimeUtc() } | ConvertTo-Json -Compress | Out-File -Encoding utf8 -Force -Append file.json
@{ DateTime = (Get-Date).DateTime } | ConvertTo-Json -Compress | Out-File -Encoding utf8 -Force -Append file.json

```

file.json

```
{"Date":{"value":"\/Date(1565580667972)\/","DisplayHint":2,"DateTime":"Monday, August 12, 2019 1:31:07 PM"}}
{"ToFileTimeUtc":132100542679805620}
{"DateTime":"Monday, August 12, 2019 1:31:07 PM"}

```

How can i get Date Types into ES?

![04](https://us1.discourse-cdn.com/elastic/original/3X/6/6/66e77c80a75f500a857c920f8b6eebd997f64e43.png)

---

<div class="post-metadata">

### Author: ![ajhstn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ajhstn/32/24629_2.png) [@ajhstn](https://discuss.elastic.co/u/ajhstn)
#### Post date: [August 12, 2019, 4:56am UTC](https://discuss.elastic.co/t/problem-with-json-date-types/194780/2 "2019-08-12T04:56:47Z")

</div>

I was able to get this partly working, if i `PUT` a `_Mapping` into ES before sending any data..

How can i format my data in the first place, and let dynamic/auto mapping occur, rather than me manually create the mapping before hand?

---

<div class="post-metadata">

### Author: ![steffens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steffens/32/79630_2.png) [@steffens](https://discuss.elastic.co/u/steffens)
#### Post date: [August 13, 2019, 9:40am UTC](https://discuss.elastic.co/t/problem-with-json-date-types/194780/3 "2019-08-13T09:40:35Z")

</div>

For timestamps you need a mapping. As JSON has no notion of time. Without mapping Elasticsearch thinks it is a string.

One normally creates a template. Beats generate templates dynamicaly (adjusting settings to the Elasticsearch version being used).

Using `setup.template.append_fields` (see: [Load the Elasticsearch index template](https://www.elastic.co/guide/en/beats/functionbeat/7.3/configuration-template.html#configuration-template)), one can add extra mappings right from within the beats config.

---

<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: [September 10, 2019, 11:40am UTC](https://discuss.elastic.co/t/problem-with-json-date-types/194780/4 "2019-09-10T11:40:36Z")

</div>

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