第一章 Elasticsearch集群
1.1 准备三台Elasticsearch服务器
创建Elasticsearch-cluster文件夹,在内部复制三个Elasticsearch服务
1.2 修改每台服务器配置
修改Elasticsearch-cluster\node*\config\Elasticsearch.yml配置文件
#节点1的配置信息:
#集群名称,保证唯一
cluster.name: my-Elasticsearch
#节点名称,必须不一样
node.name: node-1 //节点名字不同
#必须为本机的ip地址
network.host: 127.0.0.1
#服务端口号,在同一机器下必须不一样
http.port: 9201 //端口号不一样
#集群间通信端口号,在同一机器下必须不一样
transport.tcp.port: 9301 //通信端口号不一样
#设置集群自动发现机器ip集合
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
1.3创建索引和配置映射
PUT /heima2
{
"settings":{},
"mappings":{
"goods":{
"properties":{
"title":{
"type":"text",
"analyzer":"ik_max_word"
},
"subtitle":{
"type":"text",
"analyzer":"ik_max_word"
},
"images":{
"type":"keyword",
"index":"false"
},
"price":{
"type":"float"
}
}
}
}
}
1.4添加文档
POST /heima2/goods
{
"title":"小米手机",
"images":"http://image.leyou.com/12479122.jpg",
"price":2699.00
}
第二章 ElasticSearch高级Rest客户端
2.1 客户端开发环境搭建
Spring Boot集成Elasticsearch的时候,我们需要引入高阶客户端【elasticsearch-rest-high-level-client】【elasticsearch-rest-client】和【elasticsearch】来操作Elasticsearch,在引入起步依赖的时候,需要严格注意Elasticsearch和起步依赖的版本关系,否则在使用过程中会出很多问题
搭建步骤:
-
创建SpringBoot的项目,勾选starter配置
-
配置Maven依赖坐标
-
将ElasticSearch的客户端对象,注入Spring的容器
-
配置ElasticSearch,服务地址,端口号