spring-boot-starter-data-elasticsearch实体注解说明

//实体类上注解
@Document(indexName = "china")      对应的索引为china
@Setting(shards=1, replicas = 0)    创建一个索引的分片,索引的副本数量          

//属性上注解
@Field(type=FieldType.Text, analyzer=“ik_max_word”) 表示该字段是一个文本,并作最大程度拆分,默认建立索引

@Field(type=FieldType.Text,index=false) 表示该字段是一个文本,不建立索引

@Field(type=FieldType.Date) 表示该字段是一个文本,日期类型,默认不建立索引

@Field(type=FieldType.Long) 表示该字段是一个长整型,默认建立索引

@Field(type=FieldType.Keyword) 表示该字段内容是一个文本并作为一个整体不可分,默认建立索引

@Field(type=FieldType.Float) 表示该字段内容是一个浮点类型并作为一个整体不可分,默认建立索引

date 、floatlong都是不能够被拆分的

参考链接:https://blog.csdn.net/nlcexiyue/article/details/111386816
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 Spring Boot Starter Data Elasticsearch 可以轻松地在 Spring Boot 应用中集成 Elasticsearch。以下是使用步骤: 1. 添加依赖:在你的 pom.xml 文件中添加 Spring Boot Starter Data Elasticsearch 依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-elasticsearch</artifactId> </dependency> ``` 2. 配置连接:在应用的配置文件中,配置 Elasticsearch 的连接信息。例如,在 application.properties 文件中添加以下配置: ```properties spring.data.elasticsearch.cluster-nodes=localhost:9200 ``` 3. 创建实体类:创建一个与 Elasticsearch 索引文档对应的实体类,并使用注解进行映射。例如: ```java import org.springframework.data.annotation.Id; import org.springframework.data.elasticsearch.annotations.Document; @Document(indexName = "myindex", type = "mytype") public class MyDocument { @Id private String id; private String name; // Getters and setters } ``` 在上面的示例中,`@Document` 注解用于指定索引名称和类型,`@Id` 注解表示文档的唯一标识。 4. 创建仓库接口:创建一个继承自 ElasticsearchRepository 的接口,用于定义与 Elasticsearch 进行交互的方法。例如: ```java import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; public interface MyDocumentRepository extends ElasticsearchRepository<MyDocument, String> { List<MyDocument> findByName(String name); } ``` 在上面的示例中,`ElasticsearchRepository` 提供了一些基本的 CRUD 操作,你还可以定义自己的查询方法。 5. 使用仓库接口:在需要使用 Elasticsearch 的地方,通过注入仓库接口来进行操作。例如,在一个服务类中注入 `MyDocumentRepository` 并使用它执行查询: ```java import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class MyService { @Autowired private MyDocumentRepository repository; public List<MyDocument> searchByName(String name) { return repository.findByName(name); } } ``` 以上就是使用 Spring Boot Starter Data Elasticsearch 的基本步骤。你可以根据自己的需求,进行更多的配置和操作,包括自定义查询、分页等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值