是否可以动态地(在运行时)指定indexName每个@Document,例如,通过配置文件?或者是否可以使@DocumentSpring环境(dev,prod)依赖?
谢谢!
spring-mvc spring-data spring-boot spring-data-elasticsearch
SolrJ 序列化 LocalDate 和 LocalDateTime,但它们不能作为日期(或日期范围)进行搜索,而是作为字符串进行搜索。如果希望使其可搜索,则必须在使用 SolrJ 进行持久化之前将其转换为 java.util.Date。
有没有办法为 SolrJ 定义自定义序列化器或将 LocalDate 和 LocalDateTime 也标记为日期字段(因此可搜索)?
谢谢你!
编辑:代码示例
String zkHosts = "localhost:2181";
CloudSolrClient client = new CloudSolrClient.Builder().withZkHost(zkHosts).build();
client.setDefaultCollection("playground");
Person test = Person.builder().id("UID-333").createdTimestamp(LocalDateTime.now()).dateOfBirth(LocalDate.now()).gender("male").build();
client.addBean("person", test, 1000);
client.close();
Run Code Online (Sandbox Code Playgroud)
这是 Solr 中保存的内容:
{
"id":"UID-333",
"dateOfBirth":["java.time.LocalDate:2018-05-15"],
"dateOfBirth_str":["java.time.LocalDate:2018-05-15"],
"gender":["male"],
"gender_str":["male"],
"timestamp":["java.time.LocalDateTime:2018-05-15T15:00:12.433"],
"timestamp_str":["java.time.LocalDateTime:2018-05-15T15:00:12.433"]
}
Run Code Online (Sandbox Code Playgroud)
当然实体对应的属性是用 注释的@Field。