{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/8530","repository_url":"https://api.github.com/repos/elastic/elasticsearch","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/8530/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/8530/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/8530/events","html_url":"https://github.com/elastic/elasticsearch/issues/8530","id":49204978,"number":8530,"title":"Can't sort on field with custom date format mapping","user":{"login":"jensbengtsson","id":1673887,"avatar_url":"https://avatars.githubusercontent.com/u/1673887?v=3","gravatar_id":"","url":"https://api.github.com/users/jensbengtsson","html_url":"https://github.com/jensbengtsson","followers_url":"https://api.github.com/users/jensbengtsson/followers","following_url":"https://api.github.com/users/jensbengtsson/following{/other_user}","gists_url":"https://api.github.com/users/jensbengtsson/gists{/gist_id}","starred_url":"https://api.github.com/users/jensbengtsson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jensbengtsson/subscriptions","organizations_url":"https://api.github.com/users/jensbengtsson/orgs","repos_url":"https://api.github.com/users/jensbengtsson/repos","events_url":"https://api.github.com/users/jensbengtsson/events{/privacy}","received_events_url":"https://api.github.com/users/jensbengtsson/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"jpountz","id":299848,"avatar_url":"https://avatars.githubusercontent.com/u/299848?v=3","gravatar_id":"","url":"https://api.github.com/users/jpountz","html_url":"https://github.com/jpountz","followers_url":"https://api.github.com/users/jpountz/followers","following_url":"https://api.github.com/users/jpountz/following{/other_user}","gists_url":"https://api.github.com/users/jpountz/gists{/gist_id}","starred_url":"https://api.github.com/users/jpountz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpountz/subscriptions","organizations_url":"https://api.github.com/users/jpountz/orgs","repos_url":"https://api.github.com/users/jpountz/repos","events_url":"https://api.github.com/users/jpountz/events{/privacy}","received_events_url":"https://api.github.com/users/jpountz/received_events","type":"User","site_admin":false},"milestone":null,"comments":9,"created_at":"2014-11-18T10:33:33Z","updated_at":"2016-04-28T17:44:35Z","closed_at":"2014-11-25T13:44:28Z","body":"I'm running elasticsearch 1.4\r\n```javascript\r\n{\r\n\r\n    \"status\": 200,\r\n    \"name\": \"Bevatron\",\r\n    \"cluster_name\": \"poc\",\r\n    \"version\": {\r\n        \"number\": \"1.4.0\",\r\n        \"build_hash\": \"bc94bd81298f81c656893ab1ddddd30a99356066\",\r\n        \"build_timestamp\": \"2014-11-05T14:26:12Z\",\r\n        \"build_snapshot\": false,\r\n        \"lucene_version\": \"4.10.2\"\r\n    },\r\n    \"tagline\": \"You Know, for Search\"\r\n\r\n}\r\n```\r\n\r\nI have a type with the following mapping:\r\n\r\n```javascript\r\n{\r\n   \"bopo\": {\r\n      \"mappings\": {\r\n         \"ProductionTypeCapacity\": {\r\n            \"properties\": {\r\n               \"AddedDate\": {\r\n                  \"type\": \"date\",\r\n                  \"format\": \"dateOptionalTime\"\r\n               },\r\n               \"ChangedDate\": {\r\n                  \"type\": \"date\",\r\n                  \"format\": \"dateOptionalTime\"\r\n               },\r\n               \"CorporateBrandCapacities\": {\r\n                  \"type\": \"string\",\r\n                  \"index\": \"not_analyzed\"\r\n               },\r\n               \"HadesScriptUsed\": {\r\n                  \"type\": \"string\"\r\n               },\r\n               \"Key\": {\r\n                  \"type\": \"string\"\r\n               },\r\n               \"Month\": {\r\n                  \"type\": \"date\",\r\n                  \"format\": \"yyyy-MM\"\r\n               },\r\n               \"ProductionUnitId\": {\r\n                  \"type\": \"string\",\r\n                  \"index\": \"not_analyzed\"\r\n               },\r\n               \"SupplierId\": {\r\n                  \"type\": \"string\",\r\n                  \"index\": \"not_analyzed\"\r\n               }\r\n            }\r\n         }\r\n      }\r\n   }\r\n}\r\n```\r\n\r\nA hit looks like this:\r\n\r\n```javascript\r\n  {\r\n            \"_index\": \"bopo\",\r\n            \"_type\": \"ProductionTypeCapacity\",\r\n            \"_id\": \"ProductionTypeCapacity-120886-120288-2014-12\",\r\n            \"_score\": 1,\r\n            \"_source\": {\r\n               \"Key\": \"120886-120288-2014-12\",\r\n               \"AddedDate\": \"2014-03-04T02:33:04.9430000\",\r\n               \"ChangedDate\": \"2014-03-04T10:12:24.3830000\",\r\n               \"CorporateBrandCapacities\": \"Home\",\r\n               \"Month\": \"2014-12\",\r\n               \"ProductionUnitId\": \"120288\",\r\n               \"SupplierId\": \"120886\",\r\n               \"HadesScriptUsed\": \"CapacityRegistrationScript\"\r\n            }\r\n         }\r\n```\r\n\r\nWhen I execute the following query:\r\n```javascript\r\nPOST bopo/ProductionTypeCapacity/_search\r\n{\r\n  \"query\": {\r\n    \"match_all\": {}\r\n  },\r\n  \"sort\": [\r\n    {\r\n      \"Month\": {\r\n        \"order\": \"desc\"\r\n      }\r\n    }\r\n  ]\r\n}\r\n```\r\n\r\nI get this error:\r\n\r\n```javascript\r\n{\r\n   \"error\": \"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[81vkOCltQm6PWmlJSmiVog][bopo][0]: QueryPhaseExecutionException[[bopo][0]: query[ConstantScore(cache(_type:ProductionTypeCapacity))],from[0],size[10],sort[<custom:\\\"Month\\\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@149bf6c8>!]: Query Failed [Failed to execute main query]]; nested: ClassCastException[org.elasticsearch.index.fielddata.plain.AbstractAtomicOrdinalsFieldData$1 cannot be cast to org.elasticsearch.index.fielddata.AtomicNumericFieldData]; }{[81vkOCltQm6PWmlJSmiVog][bopo][1]: QueryPhaseExecutionException[[bopo][1]: query[ConstantScore(cache(_type:ProductionTypeCapacity))],from[0],size[10],sort[<custom:\\\"Month\\\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@603af23>!]: Query Failed [Failed to execute main query]]; nested: ClassCastException[org.elasticsearch.index.fielddata.plain.AbstractAtomicOrdinalsFieldData$1 cannot be cast to org.elasticsearch.index.fielddata.AtomicNumericFieldData]; }{[81vkOCltQm6PWmlJSmiVog][bopo][2]: QueryPhaseExecutionException[[bopo][2]: query[ConstantScore(cache(_type:ProductionTypeCapacity))],from[0],size[10],sort[<custom:\\\"Month\\\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@695b5d68>!]: Query Failed [Failed to execute main query]]; nested: ClassCastException[org.elasticsearch.index.fielddata.plain.AbstractAtomicOrdinalsFieldData$1 cannot be cast to org.elasticsearch.index.fielddata.AtomicNumericFieldData]; }{[81vkOCltQm6PWmlJSmiVog][bopo][3]: QueryPhaseExecutionException[[bopo][3]: query[ConstantScore(cache(_type:ProductionTypeCapacity))],from[0],size[10],sort[<custom:\\\"Month\\\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@4627c21b>!]: Query Failed [Failed to execute main query]]; nested: ClassCastException[org.elasticsearch.index.fielddata.plain.AbstractAtomicOrdinalsFieldData$1 cannot be cast to org.elasticsearch.index.fielddata.AtomicNumericFieldData]; }{[81vkOCltQm6PWmlJSmiVog][bopo][4]: QueryPhaseExecutionException[[bopo][4]: query[ConstantScore(cache(_type:ProductionTypeCapacity))],from[0],size[10],sort[<custom:\\\"Month\\\": org.elasticsearch.index.fielddata.fieldcomparator.LongValuesComparatorSource@446d2a0b>!]: Query Failed [Failed to execute main query]]; nested: ClassCastException[org.elasticsearch.index.fielddata.plain.AbstractAtomicOrdinalsFieldData$1 cannot be cast to org.elasticsearch.index.fielddata.AtomicNumericFieldData]; }]\",\r\n   \"status\": 500\r\n}\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments/215507169","html_url":"https://github.com/elastic/elasticsearch/issues/8530#issuecomment-215507169","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/8530","id":215507169,"user":{"login":"clintongormley","id":56599,"avatar_url":"https://avatars.githubusercontent.com/u/56599?v=3","gravatar_id":"","url":"https://api.github.com/users/clintongormley","html_url":"https://github.com/clintongormley","followers_url":"https://api.github.com/users/clintongormley/followers","following_url":"https://api.github.com/users/clintongormley/following{/other_user}","gists_url":"https://api.github.com/users/clintongormley/gists{/gist_id}","starred_url":"https://api.github.com/users/clintongormley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/clintongormley/subscriptions","organizations_url":"https://api.github.com/users/clintongormley/orgs","repos_url":"https://api.github.com/users/clintongormley/repos","events_url":"https://api.github.com/users/clintongormley/events{/privacy}","received_events_url":"https://api.github.com/users/clintongormley/received_events","type":"User","site_admin":false},"created_at":"2016-04-28T17:44:35Z","updated_at":"2016-04-28T17:44:35Z","body":"@bimalkeeth the new [reindex api](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/docs-reindex.html) makes reindexing really easy"}}