原因就像mysql的字段要跟Java基本类型对应一样,ES的字段也要与Java的基本类型相对应。
一、
而且这个最好新建一个ES索引库,否则可能会有问题。我用Restful操作初始化了一个ES索引库,并增加数据,再用Java操作的时候,Springboot启动会报错。
二、
还有就是实体类的Document注解indexName、Type都要有
需要检索的字段@Field(index=true),并且设置type = FieldType.Text。
package com.wheatdr.search.pojo;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import java.io.Serializable;
/**
* @Program: wheat-ear-learn
* @Description: Search
* @Author: BitterGourd
* @Date: 2020-05-14 23:58
*/
@Document(indexName = "content",type = "blog")
@Data
public class Content implements Serializable {
@Id
private String id;
// 是否索引 表示该域能被搜索 谷歌的site: title: content:
// 是否分词 表示整体匹配还是单词匹配
// 是否存储 表示是否在页面上显示
@Field(index = true,type = FieldType.Text,analyzer = "ik_max_word", searchAnalyzer = "ik_max_word")
private String title;
@Field(index = true,type = FieldType.Text,analyzer = "ik_max_word", searchAnalyzer = "ik_max_word")
private String content;
private String state;
}