Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring数据弹性搜索:序列化joda时间_Java_Jodatime_<img Src="//i.stack.imgur.com/A3TTx.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">spring Data Elasticsearch - Fatal编程技术网 spring-data-elasticsearch,Java,Jodatime,spring Data Elasticsearch" /> spring-data-elasticsearch,Java,Jodatime,spring Data Elasticsearch" />

Java Spring数据弹性搜索:序列化joda时间

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类型

我正在使用elasticsearchTemplate.index()将文档索引到elasticsearch服务器。以下是我的文件的一部分:

    @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);
  }
请参见此处的示例:

您能提供一个详细的说明吗?