elasticsearch 使用Joda time解析ZoneDateTime#toString()时失败
使用Elasticsearch 1.x(1.7.5取决于Joda time 1.6),我可以使用自定义日期时间格式“yyyy-MM-dd'HH:MM:ss.SSSZZ[ZZZ]”将通过ZoneDateTime#toString()获得的序列化字符串(例如“2016-11-29T18:47:21.766+01:00[欧洲/巴黎])解析为时间戳 使用Elasticsearch 2.4.1(这取决于Joda时间2.9.4),我再也不能这样做了。它失败,出现“java.lang.IllegalArgumentException:无效格式:”2016-11-29T18:47:21.766+01:00[欧洲/巴黎]”在“欧洲/巴黎]”异常中格式错误 编辑:这是关于ElasticSearchJavaAPI的 EDIT2:我只想将Java 8 DateTimeFormatter#ISO#ZONED(日期)时间转换为一个格式字符串,该格式字符串可以使用Joda#forPattern(字符串、区域设置)构建一个工作的Jodatime FormatDateTimeFormatter 我在TestNG测试用例中再现了这个问题:
elasticsearch 使用Joda time解析ZoneDateTime#toString()时失败,
elasticsearch,java-8,jodatime,
elasticsearch,Java 8,Jodatime,使用Elasticsearch 1.x(1.7.5取决于Joda time 1.6),我可以使用自定义日期时间格式“yyyy-MM-dd'HH:MM:ss.SSSZZ[ZZZ]”将通过ZoneDateTime#toString()获得的序列化字符串(例如“2016-11-29T18:47:21.766+01:00[欧洲/巴黎])解析为时间戳 使用Elasticsearch 2.4.1(这取决于Joda时间2.9.4),我再也不能这样做了。它失败,出现“java.lang.IllegalArgum
final ZonedDateTime now = ZonedDateTime.now();
final String strNow = now.toString();
final FormatDateTimeFormatter formatter0 = Joda.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZZ[ZZZ]", Locale.ROOT);
formatter0.parser().parseMillis(strNow);
该代码段失败,出现以下异常:
失败:parseMillisTest
java.lang.IllegalArgumentException:无效格式:“2016-11-29T18:47:21.766+01:00[欧洲/巴黎]”在“欧洲/巴黎]”处格式不正确
位于org.joda.time.format.DateTimeParserBucket.doParseMillis(DateTimeParserBucket.java:187)
位于org.joda.time.format.DateTimeFormatter.parseMillis(DateTimeFormatter.java:826)
位于org.joda.time.format.DateTimeFormatterTest.parseMillisTest(DateTimeFormatterTest.java:27)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中
位于java.lang.reflect.Method.invoke(Method.java:498)
位于org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100)
位于org.testng.internal.Invoker.invokeMethod(Invoker.java:646)
位于org.testng.internal.Invoker.invokeTestMethod(Invoker.java:811)
位于org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1137)
位于org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
位于org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
位于org.testng.TestRunner.privateRun(TestRunner.java:753)
位于org.testng.TestRunner.run(TestRunner.java:607)
位于org.testng.SuiteRunner.runTest(SuiteRunner.java:368)
在org.testng.SuiteRunner.runSequential上(SuiteRunner.java:363)
位于org.testng.SuiteRunner.privateRun(SuiteRunner.java:321)
运行(SuiteRunner.java:270)
位于org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
位于org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
在org.testng.testng.runSuitesSequentially上(testng.java:1284)
位于org.testng.testng.runSuitesLocally(testng.java:1209)
位于org.testng.testng.runSuites(testng.java:1124)
位于org.testng.testng.run(testng.java:1096)
位于org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
位于org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
从JodaTime2.9.4升级到JodaTime2.9.5解决了这个问题。 使用Elasticsearch 2.4.2(取决于jodatime 2.9.5),问题消失了。我刚刚又做了一次测试,结果通过了 我再次尝试了依赖于jodatime 2.9.4的测试,但失败了。2.9.5工作正常。
不要考虑我最后的评论,这是错误的。我一定是对依赖项做了些什么。这在Elasticsearch 2.4.2中对我有效:
PUT test{“mappings”:{“test”:{“properties”:{“date”:{“type”:“date”,“format”:“yyyy-MM-dd'T'HH:MM:ss.SSSZZ[ZZZ]}}}测试后/test/1{“date”:“2016-11-29T18:47:21.766+01:00[欧洲/巴黎]”}
这个问题在Java API中。我将编辑这个问题以精确说明这一点。在2.4.2版本中仍然存在。