{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/10304","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/10304/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/10304/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/10304/events","html_url":"https://github.com/elastic/elasticsearch/issues/10304","id":65013017,"number":10304,"title":"key_as_string is always showing up as 1970-01-01 in Date Histogram","user":{"login":"devnull52","id":8470099,"avatar_url":"https://avatars.githubusercontent.com/u/8470099?v=3","gravatar_id":"","url":"https://api.github.com/users/devnull52","html_url":"https://github.com/devnull52","followers_url":"https://api.github.com/users/devnull52/followers","following_url":"https://api.github.com/users/devnull52/following{/other_user}","gists_url":"https://api.github.com/users/devnull52/gists{/gist_id}","starred_url":"https://api.github.com/users/devnull52/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devnull52/subscriptions","organizations_url":"https://api.github.com/users/devnull52/orgs","repos_url":"https://api.github.com/users/devnull52/repos","events_url":"https://api.github.com/users/devnull52/events{/privacy}","received_events_url":"https://api.github.com/users/devnull52/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/elastic/elasticsearch/labels/feedback_needed","name":"feedback_needed","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-03-29T02:13:32Z","updated_at":"2015-04-04T01:04:10Z","closed_at":null,"body":"Using ElasticSearch 1.5.0 and datehistogram, the key_as_string is always showing up as 1970-01-01. I am using publicly available IMDB movie DB to test ES. Please advice if I am doing something wrong.\r\n\r\n```js\r\nGET /movies/movie/_search?search_type=count\r\n{\r\n    \"aggs\" : {\r\n        \"movie-releases-by-year\" : {\r\n            \"date_histogram\" : {\r\n                \"field\" : \"fields.year\",\r\n                \"interval\" : \"50\",\r\n                \"min_doc_count\": 0,\r\n                \"format\" : \"yyyy-MM-dd\" \r\n            }\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n```js\r\n{\r\n   \"took\": 2,\r\n   \"timed_out\": false,\r\n   \"_shards\": {\r\n      \"total\": 1,\r\n      \"successful\": 1,\r\n      \"failed\": 0\r\n   },\r\n   \"hits\": {\r\n      \"total\": 4903,\r\n      \"max_score\": 0,\r\n      \"hits\": []\r\n   },\r\n   \"aggregations\": {\r\n      \"movie-releases-by-year\": {\r\n         \"buckets\": [\r\n            {\r\n               \"key_as_string\": \"1970-01-01\",\r\n               \"key\": 1900,\r\n               \"doc_count\": 51\r\n            },\r\n            {\r\n               \"key_as_string\": \"1970-01-01\",\r\n               \"key\": 1950,\r\n               \"doc_count\": 1480\r\n            },\r\n            {\r\n               \"key_as_string\": \"1970-01-01\",\r\n               \"key\": 2000,\r\n               \"doc_count\": 3309\r\n            }\r\n         ]\r\n      }\r\n   }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments/89476252","html_url":"https://github.com/elastic/elasticsearch/issues/10304#issuecomment-89476252","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/10304","id":89476252,"user":{"login":"rjernst","id":289412,"avatar_url":"https://avatars.githubusercontent.com/u/289412?v=3","gravatar_id":"","url":"https://api.github.com/users/rjernst","html_url":"https://github.com/rjernst","followers_url":"https://api.github.com/users/rjernst/followers","following_url":"https://api.github.com/users/rjernst/following{/other_user}","gists_url":"https://api.github.com/users/rjernst/gists{/gist_id}","starred_url":"https://api.github.com/users/rjernst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rjernst/subscriptions","organizations_url":"https://api.github.com/users/rjernst/orgs","repos_url":"https://api.github.com/users/rjernst/repos","events_url":"https://api.github.com/users/rjernst/events{/privacy}","received_events_url":"https://api.github.com/users/rjernst/received_events","type":"User","site_admin":false},"created_at":"2015-04-04T01:04:10Z","updated_at":"2015-04-04T01:04:10Z","body":"@devnull52, @patricksurry is correct (thanks!). Date fields internally store their value as an epoch based timestamp (in milliseconds). The fact that \"key\" comes back as an int in your first posted response shows the actual value is far to low (it should be much large to be a timestamp representing e.g. the year 1950).\r\n\r\nI see your mappings have a format set for the field. IIRC, format won't work unless you pass the value as a string (otherwise it interprets as a timestamp).  Your example documents show you are passing year as an int."}}