# Date format not picked up when creating index

**URL:** <https://discuss.elastic.co/t/date-format-not-picked-up-when-creating-index/167393>\
**Category:** Elasticsearch\
**Created:** [February 7, 2019, 8:27am UTC](https://discuss.elastic.co/t/date-format-not-picked-up-when-creating-index/167393 "2019-02-07T08:27:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nednazit](https://avatars.discourse-cdn.com/v4/letter/n/d6d6ee/32.png) [@Nednazit](https://discuss.elastic.co/u/Nednazit)\
**Post date:** [February 7, 2019, 8:27am UTC](https://discuss.elastic.co/t/date-format-not-picked-up-when-creating-index/167393/1 "2019-02-07T08:27:33Z")

</div>

I created a template without any problems ( script 1)  
Then I create an index by putting data into it ( script 2)  
then when I retreve the index the timestamp column is still text ( script 3 )

=============== script 1 =====================

```auto
PUT _template/sensordata
{
  "template": "sensordata",
  "order": 1,
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    "doc": {
      "_source": {
        "enabled": false
      },
      "properties": {
        "timestamp": {
          "type": "date",
          "format": "yyyy-MM-dd hh:mm:ss"
        }
      }
    }
  }
}

```

=============== script 2 =================

```auto
PUT djan/doc/1
{
  "timestamp" : "2019-02-06 10:11:47"
}

```

============== script 3 =================

```auto
GET djan

```

=== result

```auto
{
  "djan": {
    "aliases": {},
    "mappings": {
      "doc": {
        "properties": {
          "timestamp": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    },
    "settings": {
      "index": {
        "creation_date": "1549527842637",
        "number_of_shards": "5",
        "number_of_replicas": "1",
        "uuid": "pMFsJmxrRLiemRhrhZI3uw",
        "version": {
          "created": "5060999"
        },
        "provided_name": "djan"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 7, 2019, 8:30am UTC](https://discuss.elastic.co/t/date-format-not-picked-up-when-creating-index/167393/2 "2019-02-07T08:30:33Z")

</div>

Because you created an index named `djan` but your template will be applied only on index named `sensordata`:

```auto
  "template": "sensordata",

```

By the way, you should use a more recent version, like 6.6.0.

---

<div class="post-metadata">

**Author:** ![Nednazit](https://avatars.discourse-cdn.com/v4/letter/n/d6d6ee/32.png) [@Nednazit](https://discuss.elastic.co/u/Nednazit)\
**Post date:** [February 7, 2019, 8:46am UTC](https://discuss.elastic.co/t/date-format-not-picked-up-when-creating-index/167393/3 "2019-02-07T08:46:52Z")

</div>

I looked in the orginal code I had then I found out I was mixing templates with names (  
like sensordata\* ) ( djan was just an example) and the order they were used was not correct.

Tanks for the quick respons

additional question we get data in a timezone moscow without timezone. Can I add timezone?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 7, 2019, 9:32am UTC](https://discuss.elastic.co/t/date-format-not-picked-up-when-creating-index/167393/4 "2019-02-07T09:32:20Z")

</div>

You can use an ingest pipeline with a date processor to process your date as you wish.

See [https://www.elastic.co/guide/en/elasticsearch/reference/6.6/date-processor.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.6/date-processor.html)

---

<div class="post-metadata">

**Author:** ![Nednazit](https://avatars.discourse-cdn.com/v4/letter/n/d6d6ee/32.png) [@Nednazit](https://discuss.elastic.co/u/Nednazit)\
**Post date:** [February 9, 2019, 9:45am UTC](https://discuss.elastic.co/t/date-format-not-picked-up-when-creating-index/167393/5 "2019-02-09T09:45:23Z")

</div>

I try to convert a date when the index is build. As I understood I can use pipelines. I got my training stuff, google and tried. But something i going wrong.

delete datetestz  
delete \_template/datetempz

put \_template/datetempz  
{  
"index\_patterns": "datetestz",  
"mappings": {  
"doc": {  
"properties": {  
"datefield": { "type": "date",  
"format": "yyyy-MM-dd HH:mm:ss"  
}  
}  
}  
}  
}

put \_ingest/pipeline/datconvert  
{  
"description" : "...",  
"processors" : [  
{  
"date" : {  
"field" : "datefield",  
"target\_field": "tdatefield",  
"formats" : ["yyyy-MM-dd HH:mm:ss"],  
"timezone" : "Europe/London"  
}  
}  
]  
}

-------- amsterdam time ------------  
put datetestz/doc/1  
{  
"datefield": "2019-09-02 15:00:11",  
"tdatefield" :""  
}

I hoped tdatefield was set with the london time.  
GET datetestz/\_search

============= result ===========  
{  
"took" : 2,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"skipped" : 0,  
"failed" : 0  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 1.0,  
"hits" : [  
{  
"\_index" : "datetestz",  
"\_type" : "doc",  
"\_id" : "1",  
"\_score" : 1.0,  
"\_source" : {  
"datefield" : "2019-09-02 15:00:11",  
"tdatefield" : "" \<\<=== this must be 2019-09-02 14:00:11 but it is not  
}  
}  
]  
}  
}

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 9, 2019, 1:22pm UTC](https://discuss.elastic.co/t/date-format-not-picked-up-when-creating-index/167393/6 "2019-02-09T13:22:06Z")

</div>

Most likely this is because you are providing it as an empty value.

Here is a script to test it properly. Note that it's well formatted to be easily readable and using uppercase HTTP verbs to make it usable in a Kibana console.  
Please next time, make sure you paste similar code. It will reduce the time needed to test your code.

```auto
POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "description": "...",
    "processors": [
      {
        "date": {
          "field": "datefield",
          "target_field": "tdatefield",
          "formats": [
            "yyyy-MM-dd HH:mm:ss"
          ],
          "timezone": "Europe/London"
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "datefield": "2019-09-02 15:00:11"
      }
    }
  ]
}

```

Gives:

```auto
{
  "docs" : [
    {
      "doc" : {
        "_index" : "_index",
        "_type" : "_type",
        "_id" : "_id",
        "_source" : {
          "datefield" : "2019-09-02 15:00:11",
          "tdatefield" : "2019-09-02T15:00:11.000+01:00"
        },
        "_ingest" : {
          "timestamp" : "2019-02-09T13:19:29.817848Z"
        }
      }
    }
  ]
}

```

Where `"tdatefield" : "2019-09-02T15:00:11.000+01:00"` seems to be OK to me.

---

<div class="post-metadata">

**Author:** ![Nednazit](https://avatars.discourse-cdn.com/v4/letter/n/d6d6ee/32.png) [@Nednazit](https://discuss.elastic.co/u/Nednazit)\
**Post date:** [February 10, 2019, 8:28am UTC](https://discuss.elastic.co/t/date-format-not-picked-up-when-creating-index/167393/7 "2019-02-10T08:28:50Z")

</div>

Thx for the reply I look into it today

---

<div class="post-metadata">

**Author:** ![Nednazit](https://avatars.discourse-cdn.com/v4/letter/n/d6d6ee/32.png) [@Nednazit](https://discuss.elastic.co/u/Nednazit)\
**Post date:** [February 10, 2019, 8:55pm UTC](https://discuss.elastic.co/t/date-format-not-picked-up-when-creating-index/167393/8 "2019-02-10T20:55:24Z")

</div>

Thanks for your help, it made me understand this date topic. I played with the pipeline UTC CET etc.

Tomorrow I'll discuss it with the business and see if I understood there problem.

---

<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:** [March 10, 2019, 8:55pm UTC](https://discuss.elastic.co/t/date-format-not-picked-up-when-creating-index/167393/9 "2019-03-10T20:55:39Z")

</div>

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