# ES default date type not taking nanos

**URL:** https://discuss.elastic.co/t/es-default-date-type-not-taking-nanos/322614
**Category:** Elasticsearch
**Tags:** docker
**Created:** [January 6, 2023, 11:50am UTC](https://discuss.elastic.co/t/es-default-date-type-not-taking-nanos/322614 "2023-01-06T11:50:17Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![samee\_alam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/samee_alam/32/100877_2.png) [@samee\_alam](https://discuss.elastic.co/u/samee_alam)
#### Post date: [January 6, 2023, 11:50am UTC](https://discuss.elastic.co/t/es-default-date-type-not-taking-nanos/322614/1 "2023-01-06T11:50:17Z")

</div>

ES version 7.17.3

Fluentd config is as below:

```
    time_key timestamp
    time_format %Y-%m-%dT%H:%M:%S.%N%Z

```

which takes nano seconds into consideration and data is stored properly in elasticsearch as:

 ![1](https://us1.discourse-cdn.com/elastic/original/3X/f/e/fe49494e46f91d5911cb7b91a980d9b36d1cbf70.jpeg)

But default data type in mapping properties of index is "date"

 ![2](https://us1.discourse-cdn.com/elastic/original/3X/6/c/6c29867ace6b5d7f3640b6f34abc01feefaf0dd8.jpeg)

This is creating problem in sorting, as type "date" considers only milli seconds and documents are being sorted in wrong order for whom the difference is at nano second level.

How do I set the default date type as "date\_nanos" ?

I know I can delete and re-create the index and type date\_nanos and reindex it, but I cannot do this in production. So basically, by default it should take date\_nanos.

Please suggest how I can configure this.  
Also I am using helm charts, so configuration to be done at ES chart possible?

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [January 6, 2023, 1:28pm UTC](https://discuss.elastic.co/t/es-default-date-type-not-taking-nanos/322614/2 "2023-01-06T13:28:44Z")

</div>

> [@samee\_alam](#):
>
> I know I can delete and re-create the index and type date\_nanos and reindex it, but I cannot do this in production. So basically, by default it should take date\_nanos.

Unfortunately i think this is the only way to change, you need to explictily map the field to use `date_nanos`, so for any existing date you need to change the mapping and reindex.

For new indices you can use a dynamic template to map any date type as `date_nanos`.

Something like this, I guess:

```auto
    "dynamic_templates": [
      {
        "date_nano": {
          "match_mapping_type": "date",
          "mapping": {
            "type": "date_nanos"
          }
        }
      }

```

---

<div class="post-metadata">

### Author: ![samee\_alam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/samee_alam/32/100877_2.png) [@samee\_alam](https://discuss.elastic.co/u/samee_alam)
#### Post date: [January 11, 2023, 11:19am UTC](https://discuss.elastic.co/t/es-default-date-type-not-taking-nanos/322614/3 "2023-01-11T11:19:58Z")

</div>

Thanks for your response.  
As suggested I am creating an index template and mapped the field "date" to "date\_nanos".

Once ES is up, as part of the readiness probe, using curl, I am pushing this to ES, so once data starts coming to ES, date is taken as date\_nanos.

---

<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: [February 8, 2023, 11:20am UTC](https://discuss.elastic.co/t/es-default-date-type-not-taking-nanos/322614/4 "2023-02-08T11:20:47Z")

</div>

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