{
"mappings": {
"properties": {
"id": {
"type": "long"
},
"title": {
"type": "text",
"analyzer": "ik_smart"
},
"subTitle": {
"type": "text",
"analyzer": "ik_smart"
},
"tag": {
"type": "text",
"analyzer": "ik_smart"
},
"content": {
"type": "text",
"analyzer": "ik_smart"
},
"userId": {
"type": "long"
},
"createTime": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
}
}
}
}这是我的索引
@Data
@TableName("post")
@Document(indexName = "posts")
public class Post {
@TableId(value = "id",type = IdType.ASSIGN_ID)
@Id
private Long id;
…
…
@TableField(fill = FieldFill.INSERT)
@Field(type = FieldType.Date, format = DateFormat.epoch_millis)
private Timestamp createTime;
}
这是我的实体类
ERROR 14400 --- [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.Date] to type [java.sql.Timestamp]] with root cause
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.Date] to type [java.sql.Timestamp]
这是我的报错,就是ES存储时间戳是可以的,但是search读取时映射出现问题
// 搜索帖子
@GetMapping("/search")
public List<Post> searchPosts(@RequestParam String keyword) {
return postServiceImpl.searchPosts(keyword);
}
// 搜索帖子(基于Elasticsearch)
public List<Post> searchPosts(String keyword) {
// 使用 Elasticsearch 的全文搜索功能
return postRepository.findByTitleContaining(keyword);
}
public interface PostRepository extends ElasticsearchRepository<Post,Long> {
// 可以扩展自定义查询方法,例如按标题搜索
List<Post> findByTitleContaining(String keyword);
}