es的Date類型支持的格式是有限的,默認是一個時間戳,可讀性不是很好,需要解析之后才能使用,而它默認支持的格式只有如下幾種,如果你在java里格式化的字符串不屬於以下幾種,將會出錯。
UTC時間
//kibana里索引字段
@Field(type = FieldType.Date, format = DateFormat.custom, pattern ="yyyy-MM-ddTHH:mm:ss.SSSZ")// 指定存儲格式
@JsonFormat(pattern ="yyyy-MM-dd HH:mm:ss", timezone ="GMT+8")// 數據格式轉換,並加上8小時進行存儲
private String timestamp;
esPathHandlerEntity.setTimestamp(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()));
esPathHandlerRepository.save(esPathHandlerEntity);
本地時間,kibana里索引需要這樣做
//kibana里索引字段
@Field(type = FieldType.Date, format = DateFormat.custom, pattern ="yyyy-MM-ddTHH:mm:ss+0800")// 指定存儲格式
@JsonFormat(pattern ="yyyy-MM-dd HH:mm:ss", timezone ="GMT+8")// 數據格式轉換,並加上8小時進行存儲
esPathHandlerEntity.setTimestamp(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss+0800").format(new Date()));
esPathHandlerRepository.save(esPathHandlerEntity);
上面的配置與kibana里配置時間選擇使用“瀏覽器”時間是統一的