在java elasticsearch中存储日期时间

时间:2016-05-07 22:32:28

标签: java elasticsearch spring-data

我正在尝试存储正在创建的实体的日期时间。我使用org.joda.time.DateTime.now()创建了一个DateTime对象。但它作为

存储在elasticsearch中
{"centuryOfEra":20,"yearOfEra":2016,"yearOfCentury":16,"weekyear":2016,"monthOfYear":5,"weekOfWeekyear":18,"hourOfDay":15,"minuteOfHour":25,"secondOfMinute":28,"millisOfSecond":431,"dayOfYear":128,"year":2016,"dayOfMonth":7,"dayOfWeek":6,"era":1,"millisOfDay":55528431,"secondOfDay":55528,"minuteOfDay":925,"chronology":{"zone":{"fixed":false,"uncachedZone":{"cachable":true,"fixed":false,"id":"America/Los_Angeles"}

有没有办法指定像May 07 2016 14:58:44那样存储对象的格式?如果我们将它存储为字符串,我们仍然可以获得进行范围查询的性能优势吗?

2 个答案:

答案 0 :(得分:0)

继续学习并尝试合成你的约会对象;)

http://www.joda.org/joda-time/userguide.html

答案 1 :(得分:0)

您可以使用带有格式字符串的toString()方法:

String dateStr = datetime.toString("dd:MM:yy");