{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/21121","repository_url":"https://api.github.com/repos/elastic/elasticsearch","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/21121/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/21121/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/21121/events","html_url":"https://github.com/elastic/elasticsearch/issues/21121","id":185252553,"number":21121,"title":"5.0.0-rc Painless support for working with dates","user":{"login":"niemyjski","id":1020579,"avatar_url":"https://avatars.githubusercontent.com/u/1020579?v=3","gravatar_id":"","url":"https://api.github.com/users/niemyjski","html_url":"https://github.com/niemyjski","followers_url":"https://api.github.com/users/niemyjski/followers","following_url":"https://api.github.com/users/niemyjski/following{/other_user}","gists_url":"https://api.github.com/users/niemyjski/gists{/gist_id}","starred_url":"https://api.github.com/users/niemyjski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niemyjski/subscriptions","organizations_url":"https://api.github.com/users/niemyjski/orgs","repos_url":"https://api.github.com/users/niemyjski/repos","events_url":"https://api.github.com/users/niemyjski/events{/privacy}","received_events_url":"https://api.github.com/users/niemyjski/received_events","type":"User","site_admin":false},"labels":[{"id":322176648,"url":"https://api.github.com/repos/elastic/elasticsearch/labels/:Plugin%20Lang%20Painless","name":":Plugin Lang Painless","color":"009800","default":false},{"id":111416437,"url":"https://api.github.com/repos/elastic/elasticsearch/labels/discuss","name":"discuss","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":10,"created_at":"2016-10-25T22:37:57Z","updated_at":"2016-10-31T18:06:17Z","closed_at":null,"body":"I'm upgrading from groovy to painless and it's not so painless so far. I wanted to post this here as I think this would be a pretty common scenario and I'm having trouble with dates (gotta love dates)\n\n``` json\nPUT /test-stacks-v1\n{\n  \"aliases\": {\n    \"test-stacks\": {}\n  },\n  \"mappings\": {\n    \"stacks\": {\n      \"_all\": {\n        \"enabled\": false\n      },\n      \"dynamic\": false,\n      \"properties\": {\n        \"id\": {\n          \"type\": \"keyword\"\n        },\n        \"first_occurrence\": {\n          \"type\": \"date\"\n        },\n        \"last_occurrence\": {\n          \"type\": \"date\"\n        },\n        \"total_occurrences\": {\n          \"type\": \"float\"\n        }\n      }\n    }\n  }\n}\n\nPUT /test-stacks/stacks/1ecd0826e447a44e78877ab1\n{\n  \"id\": \"1ecd0826e447a44e78877ab1\",\n  \"total_occurrences\": 0,\n  \"first_occurrence\": \"0001-01-01T00:00:00\",\n  \"last_occurrence\": \"0001-01-01T00:00:00\"\n}\n\nPOST /test-stacks/stacks/1ecd0826e447a44e78877ab1/_update?retry_on_conflict=3\n{\n  \"script\": { \n    \"params\": {\n      \"minOccurrenceDateUtc\": \"2016-10-25T22:04:19.3272056Z\",\n      \"maxOccurrenceDateUtc\": \"2016-10-25T22:04:19.3272056Z\",\n      \"count\": 1\n    },\n    \"inline\": \"if (ctx._source.total_occurrences == 0 || ctx._source.first_occurrence > params.minOccurrenceDateUtc) { ctx._source.first_occurrence = params.minOccurrenceDateUtc; } if (ctx._source.last_occurrence < params.maxOccurrenceDateUtc) { ctx._source.last_occurrence = params.maxOccurrenceDateUtc; } ctx._source.total_occurrences += params.count;\"\n  }\n}\n```\n\nThe last script update returns\n\n``` json```\n{\n  \"error\": {\n    \"root_cause\": [\n      {\n        \"type\": \"remote_transport_exception\",\n        \"reason\": \"[8mJiEA3][local[1]][indices:data/write/update[s]]\"\n      }\n    ],\n    \"type\": \"illegal_argument_exception\",\n    \"reason\": \"failed to execute script\",\n    \"caused_by\": {\n      \"type\": \"script_exception\",\n      \"reason\": \"runtime error\",\n      \"caused_by\": {\n        \"type\": \"class_cast_exception\",\n        \"reason\": \"Cannot apply [<] operation to types [java.lang.String] and [java.lang.String].\"\n      },\n      \"script_stack\": [\n        \"if (ctx._source.last_occurrence < params.maxOccurrenceDateUtc) { \",\n        \"                                        ^---- HERE\"\n      ],\n      \"script\": \"if (ctx._source.total_occurrences == 0 || ctx._source.first_occurrence > params.minOccurrenceDateUtc) { ctx._source.first_occurrence = params.minOccurrenceDateUtc; } if (ctx._source.last_occurrence < params.maxOccurrenceDateUtc) { ctx._source.last_occurrence = params.maxOccurrenceDateUtc; } ctx._source.total_occurrences += params.count;\",\n      \"lang\": \"painless\"\n    }\n  },\n  \"status\": 400\n}\n```\n\nThe original groovy script worked flawlessly in 1.7.5 (including linebreaks)\n\n``` cs\n            var request = new UpdateRequest<Stack, Stack>(GetIndexById(stackId), ElasticType.Type, stackId) {\n                RetryOnConflict = 3,\n                Script = @\"if (ctx._source.total_occurrences == 0 || ctx._source.first_occurrence > minOccurrenceDateUtc) {\n                            ctx._source.first_occurrence = minOccurrenceDateUtc;\n                            }\n                            if (ctx._source.last_occurrence < maxOccurrenceDateUtc) {\n                            ctx._source.last_occurrence = maxOccurrenceDateUtc;\n                            }\n                            ctx._source.total_occurrences += count;\",\n                Params = new Dictionary<string, object>(3) {\n                    { \"minOccurrenceDateUtc\", minOccurrenceDateUtc },\n                    { \"maxOccurrenceDateUtc\", maxOccurrenceDateUtc },\n                    { \"count\", count }\n                }\n            };\n```\n\nIs there anything special I need to do to cast a field (which is mapped as a date) and stored as a string to a date reliably? \n"},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments/257372239","html_url":"https://github.com/elastic/elasticsearch/issues/21121#issuecomment-257372239","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/21121","id":257372239,"user":{"login":"jdconrad","id":2126764,"avatar_url":"https://avatars.githubusercontent.com/u/2126764?v=3","gravatar_id":"","url":"https://api.github.com/users/jdconrad","html_url":"https://github.com/jdconrad","followers_url":"https://api.github.com/users/jdconrad/followers","following_url":"https://api.github.com/users/jdconrad/following{/other_user}","gists_url":"https://api.github.com/users/jdconrad/gists{/gist_id}","starred_url":"https://api.github.com/users/jdconrad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdconrad/subscriptions","organizations_url":"https://api.github.com/users/jdconrad/orgs","repos_url":"https://api.github.com/users/jdconrad/repos","events_url":"https://api.github.com/users/jdconrad/events{/privacy}","received_events_url":"https://api.github.com/users/jdconrad/received_events","type":"User","site_admin":false},"created_at":"2016-10-31T18:06:16Z","updated_at":"2016-10-31T18:06:16Z","body":"@nik9000 Point 1 to me is certainly the most interesting here.  On point 3, I thought @rjernst made the change to Date fields to expose these things as dates?  Maybe I'm misremembering, though.  I think for compatibility with Groovy, it's best effort, but if something doesn't make sense or we agree it's a poor feature we should definitely not be forced to implement it."}}
{"actor":{"display_login":"jdconrad"}}