Java Spring数据弹性搜索:序列化joda时间
我正在使用elasticsearchTemplate.index()将文档索引到elasticsearch服务器。以下是我的文件的一部分:Java Spring数据弹性搜索:序列化joda时间,java,jodatime,
spring-data-elasticsearch,Java,Jodatime,
spring Data Elasticsearch,我正在使用elasticsearchTemplate.index()将文档索引到elasticsearch服务器。以下是我的文件的一部分: @Field(type = FieldType.Date, format = DateFormat.basic_date, index = FieldIndex.not_analyzed) private Date date; 保存文档时,日期以长格式保存(以毫秒为单位),这是预期的行为。 现在,在同一个文档中,我想添加JodaTime类型
@Field(type = FieldType.Date, format = DateFormat.basic_date, index = FieldIndex.not_analyzed)
private Date date;
保存文档时,日期以长格式保存(以毫秒为单位),这是预期的行为。
现在,在同一个文档中,我想添加JodaTime类型的创建和修改的时间戳。以下是时间戳:
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssZ")
@Field(type = FieldType.Date, format = DateFormat.basic_date, index = FieldIndex.not_analyzed)
private DateTime createdDateTime;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ssZ")
@Field(type = FieldType.Date, format = DateFormat.basic_date, index = FieldIndex.not_analyzed)
private DateTime modifiedDateTime;
现在,当我保存文档时,这两个对象被存储为复杂对象(包含monthOfYear、dayOfMonth、hourOfDay等组件)。但是,我希望这些字段像日期字段(即长时间戳)一样存储。我应该换哪一种
我曾尝试在我的应用程序中将ObjectMapper和jodaModule定义为bean,但它似乎没有起到作用。有人能帮忙吗
感谢使用您自己的ObjectMapper,您需要实现允许注入ObjectMapper的EntityMapper
@Bean
@Autowired
public EntityMapper mapper(ObjectMapper objectMapper) {
return new ConfigurableEntityMapper(objectMapper);
}
然后使用创建模板
@Bean
public ElasticsearchOperations elasticsearchTemplate(Client client, EntityMapper mapper) {
return new ElasticsearchTemplate(client, mapper);
}
请参见此处的示例:您能提供一个详细的说明吗?