简体   繁体   中英

Storing date time in java elasticsearch

I am trying to store the date time of an entity that is being created. I used org.joda.time.DateTime.now() to create a DateTime object. But it gets stored in the elasticsearch as

{"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"}

is there a way to specify a format in which the object gets stored like May 07 2016 14:58:44 ? If we store it as strings would we still get the performance advantage of doing range queries?

Go on the doc and try to formate your date ;)

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

您可以将toString()方法与格式字符串一起使用:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM