SpringBoot集成ElasticSearch

安装ElasticSearch

官方下载地址:https://www.elastic.co/downloads/elasticsearch
解压:elasticsearch-5.2.2.zip
启动:bin目录 elasticsearch.bat
config目录中jvm.options
占用内存大小设置
-Xms1g
-Xmx1g
验证:访问http://localhost:9200/

安装IK分词器

https://github.com/medcl/elasticsearch-analysis-ik
解压elasticsearch-analysis-ik-5.2.2.zip里面的东西放到ElasticSearch的plugins/ik中
测试分词器:
测试分词器
POST _analyze
{
“analyzer”:“ik_smart”,
“text”:“在全文检索理论中,文档的查询是通过关键字查询文档索引来进行匹配”
}
注意:IK分词器有两种类型,分别是ik_smart分词器和ik_max_word分词器。
ik_smart: 会做最粗粒度的拆分。
ik_max_word: 会将文本做最细粒度的拆分。

安装Kibana

可视化工具:kibana客户端
Kibana5.2.2下载地址:https://www.elastic.co/downloads/kibana
解压:kibana-5.2.2-windows-x86.zip
启动:bin目录kibana.bat ----自动连上ElasticSearch 127.0.0.1:9200
访问:http://localhost:5601

SpringBoot集成ElasticSearch

1、导包
<!--springboot 对spring data es支持-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
2、application.yml
spring:
  data:
    elasticsearch:
      cluster-name: elasticsearch
      cluster-nodes: 127.0.0.1:9300 #9200是图形界面端,9300代码端
3、文档对象
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;
//查询展示的列,查询条件的列,排序的列
@Document(indexName = "hrm",type = "course")
public class CourseDoc {
   
    //文档id,数据id
    @Id
    private Long id;

    //标题
    @Field(type =FieldType.Text,analyzer = "ik_max_word",searchAnalyzer = "ik_max_word")
    private String name;

    @Field(type = FieldType.Keyword)
    private String gradeName;
}
4、自定义接口继承ElasticsearchRepository

就相当于Dao接口

import org.springframework.data.elasticsearch.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值