# Elastic search automatically changing the date type field year value to 1970

**URL:** https://discuss.elastic.co/t/elastic-search-automatically-changing-the-date-type-field-year-value-to-1970/209749
**Category:** Elasticsearch
**Created:** [November 27, 2019, 7:01pm UTC](https://discuss.elastic.co/t/elastic-search-automatically-changing-the-date-type-field-year-value-to-1970/209749 "2019-11-27T19:01:31Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![dhshaw](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@dhshaw](https://discuss.elastic.co/u/dhshaw)
#### Post date: [November 27, 2019, 7:01pm UTC](https://discuss.elastic.co/t/elastic-search-automatically-changing-the-date-type-field-year-value-to-1970/209749/1 "2019-11-27T19:01:31Z")

</div>

I am using Elastic search version 7.2 and my date field mapping is  
"agent\_utc\_time": {  
"type": "date",  
"format": "MM/dd/YYYY HH:mm:ss || MM/dd/YYYY || YYYY-MM-dd"  
},

I am inserting the date value as: "agent\_utc\_time":"07/24/2019 00:00:00"

After inserting/adding, when searching the field I see the date year value looks like ( agent\_utc\_time: Jul 24, 1970 @ 20:00:00.000)  
Year got updated to 1970, not sure what's going wrong?

Thanks!

Dharmendra

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [November 28, 2019, 9:10am UTC](https://discuss.elastic.co/t/elastic-search-automatically-changing-the-date-type-field-year-value-to-1970/209749/2 "2019-11-28T09:10:36Z")

</div>

can you share a fully reproducible example, including index/mapping creation (optional pipelines) and a sample document and a sample query that you tried this out with?

Thank you!

---

<div class="post-metadata">

### Author: ![dhshaw](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@dhshaw](https://discuss.elastic.co/u/dhshaw)
#### Post date: [December 2, 2019, 8:44pm UTC](https://discuss.elastic.co/t/elastic-search-automatically-changing-the-date-type-field-year-value-to-1970/209749/3 "2019-12-02T20:44:13Z")

</div>

Thanks Alexander for your response!

I have created mapping as-

https://:9200/dsdg\_events1  
Method: PUT  
Header: "Content-Type: application/json"  
Body:  
{  
"settings" : {  
"number\_of\_shards" : 3,  
"number\_of\_replicas" : 2  
},  
"mappings": {  
"dynamic":false,  
"properties": {  
"agent\_utc\_time": {  
"type": "date",  
"format": "MM/dd/YYYY HH:mm:ss || MM/dd/YYYY || YYYY-MM-dd"  
},  
"agent\_version": {  
"type": "keyword"  
},  
...  
...there are many other fields  
}  
}  
}

* * *

Creating the index using java code here:

## url = new URL("https://:9200/\_bulk"); conn = (HttpsURLConnection) url.openConnection(); conn.setDoInput(true); conn.setDoOutput(true); conn.setRequestProperty("Accept", "application/json"); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestMethod("POST"); OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream(), "UTF-8"); writer.write(\<\>); writer.close(); int responseCode = conn.getResponseCode();

Bulk Request Body:  
{ "index" : { "\_index" : "dsdg\_events1", "\_id" : "CEB493CA-EC73-103C-9DC8-806E7F0EE8F7" } }  
{"agent\_utc\_time":"07/25/2019 00:00:00", "agent\_version":"7.5.1","computer\_type":"Windows","machine\_domain\_name":"partners", .....}

When I search the doc on Kibana : agent\_utc\_time Jul 24, 1970 @ 20:00:00.000  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/0/f04d2efe8cd39e096ee48338258df905ff0bab5a.png)

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [December 3, 2019, 9:57am UTC](https://discuss.elastic.co/t/elastic-search-automatically-changing-the-date-type-field-year-value-to-1970/209749/4 "2019-12-03T09:57:08Z")

</div>

can you please create a curl/dev-tools reproducible example that I can copy & paste for testing. Extracting the information from your snippets, modifying them and then putting them into a curl command takes a lot of time in a voluntarily run forum.

Thanks a lot!

---

<div class="post-metadata">

### Author: ![dhshaw](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@dhshaw](https://discuss.elastic.co/u/dhshaw)
#### Post date: [December 3, 2019, 3:50pm UTC](https://discuss.elastic.co/t/elastic-search-automatically-changing-the-date-type-field-year-value-to-1970/209749/5 "2019-12-03T15:50:05Z")

</div>

Hi Alexander,

Looks like date is getting index properly on Elastic search. CURL commands:

Create mapping:  
curl -X PUT -H "Content-Type: application/json" -d '{"settings" : {"number\_of\_shards" : 3,"number\_of\_replicas" : 2},"mappings": {"dynamic":false,"properties": {"agent\_utc\_time": {"type": "date","format": "MM/dd/YYYY HH:mm:ss || MM/dd/YYYY || YYYY-MM-dd"},"agent\_version": {"type": "keyword"},"application": {"type": "keyword"},"app\_type": {"type": "keyword"},"event\_id": {"type": "keyword"}}}}' -k https://:9200/dsdg\_events2

Insert doc:  
curl -X POST -H "Content-Type: application/json; charset=UTF-8" -d '{"agent\_utc\_time":"07/25/2019 00:00:00","agent\_version":"7.5.1.0065","application":"outlook.exe","app\_type":"Email","event\_id":"CEB493CA-EC73-103C-9DC8-806E7F0EE8F7"}' -k https://:9200/dsdg\_events2/\_doc/CEB493CA-EC73-103C-9DC8-806E7F0EE8F7

Get the doc:  
curl -X GET -k [https://icam-es7-02:9200/dsdg\_events2/\_doc/CEB493CA-EC73-103C-9DC8-806E7F0EE8F7](https://icam-es7-02:9200/dsdg_events2/_doc/CEB493CA-EC73-103C-9DC8-806E7F0EE8F7)

{"\_index":"dsdg\_events2","\_type":"\_doc","\_id":"CEB493CA-EC73-103C-9DC8-806E7F0EE8F7","\_version":1,"\_seq\_no":0,"\_primary\_term":1,"found":true,"\_source":{"agent\_utc\_time":"07/25/2019 00:00:00","agent\_version":"7.5.1.0065","application":"outlook.exe","app\_type":"Email","event\_id":"CEB493CA-EC73-103C-9DC8-806E7F0EE8F7"}}

Here everything looks perfect but when I create index pattern on Kibana with the option "I don't want to use the Time Filter" selected on time filter field(attached screenshot):

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/6/a/6a0ceee5b4c96b99c39821fbbaa26836c59bedd0.png)  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/9/5989072bf6caa694c7e6ec1c2bf40e028e5cbc6a.png)

And after if I search for the indexed doc on kibana I see the date as Jul 24 1970 as attached screen shot bellow

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/4/b/4b2666d16a0db4f35ce6efaa26fdc775976a9ed3.png)

Even I create index pattern on Kibana using Time Filter "field name: agent\_utc\_time" when I search the document on Kibana it's showing wrong date year, day and time as attached screen shot below

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/c/5c071d9612a1d59596bdeeb968f42bc8b5b515aa.png)

Not sure if I am doing something wrong.

I am a Full Stack Java developer and new to Elastic search, I am sorry for simple and basic questions.

Thanks a lot!

Regards,  
Dharmendra

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [December 4, 2019, 12:59pm UTC](https://discuss.elastic.co/t/elastic-search-automatically-changing-the-date-type-field-year-value-to-1970/209749/6 "2019-12-04T12:59:12Z")

</div>

just tested it locally under a 7.5.0 instance and the index pattern worked.

Can you share the mapping of that index?

---

<div class="post-metadata">

### Author: ![dhshaw](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@dhshaw](https://discuss.elastic.co/u/dhshaw)
#### Post date: [December 4, 2019, 2:40pm UTC](https://discuss.elastic.co/t/elastic-search-automatically-changing-the-date-type-field-year-value-to-1970/209749/7 "2019-12-04T14:40:53Z")

</div>

I have already shared the mapping curl command above.  
sharing it here again. I am using version 7.2

Create mapping:  
curl -X PUT -H "Content-Type: application/json" -d '{"settings" : {"number\_of\_shards" : 3,"number\_of\_replicas" : 2},"mappings": {"dynamic":false,"properties": {"agent\_utc\_time": {"type": "date","format": "MM/dd/YYYY HH:mm:ss || MM/dd/YYYY || YYYY-MM-dd"},"agent\_version": {"type": "keyword"},"application": {"type": "keyword"},"app\_type": {"type": "keyword"},"event\_id": {"type": "keyword"}}}}' -k https://:9200/dsdg\_events2

Not sure if it's a bug on this version #7.2.

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [December 4, 2019, 4:38pm UTC](https://discuss.elastic.co/t/elastic-search-automatically-changing-the-date-type-field-year-value-to-1970/209749/8 "2019-12-04T16:38:13Z")

</div>

sorry for not being clear. With sharing I meant, that receiving the mapping actually returned the same mapping.

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [December 4, 2019, 5:02pm UTC](https://discuss.elastic.co/t/elastic-search-automatically-changing-the-date-type-field-year-value-to-1970/209749/9 "2019-12-04T17:02:26Z")

</div>

I think I found the problem. You should use `yyyy` instead of `YYYY` - which is a week based year and presumably not what you are after. See [https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html](https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html)

---

<div class="post-metadata">

### Author: ![dhshaw](https://avatars.discourse-cdn.com/v4/letter/d/d07c76/32.png) [@dhshaw](https://discuss.elastic.co/u/dhshaw)
#### Post date: [December 4, 2019, 6:32pm UTC](https://discuss.elastic.co/t/elastic-search-automatically-changing-the-date-type-field-year-value-to-1970/209749/10 "2019-12-04T18:32:27Z")

</div>

Thanks a lot Alexander for your time to debugging and helping me.

---

<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 1, 2020, 6:32pm UTC](https://discuss.elastic.co/t/elastic-search-automatically-changing-the-date-type-field-year-value-to-1970/209749/11 "2020-01-01T18:32:35Z")

</div>

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