一:1.ES是什么
ES全称ElasticSearch,是一个基于Lucene的搜索服务器。
ElasticSearch是基于Java开发的,并作为Apache许可条款下的开放源码发布,是一种流行的企业级搜索引擎。
2. ElasticSearch的使用场景
- 云计算。能够达到实时搜索、稳定、可靠、快速、安装使用方便。
- 搜索各种文档。
3. ElasticSearch的主要特点:
- 分布式(无需人工搭建集群,solr就需要人为配置,使用Zookeeper作为注册中心)
- 高可用
- 异步写入
- 多API(一切API都遵循RESTful原则,容易上手近实时搜索,数据更新在ElasticSearch中几乎完全同步)
- 面向文档
二:Springboot整合ES
添加Maven依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
配置application.yml
spring:
elasticsearch:
rest:
uris: 192.168.1.81:9200
三:ES常用命令
ES Restful API GET、POST、PUT、DELETE、HEAD含义:
1)GET:获取请求对象的当前状态。
2)POST:改变对象的当前状态。
3)PUT:创建一个对象。
4)DELETE:销毁对象。
5)HEAD:请求获取对象的基础信息。
1、查询所有索引
curl -XGET http://localhost:9200/_cat/indices?pretty
2、查询索引中的数据
curl -XGET 'http://127.0.0.1:9200/my_index/_mapping?pretty=1'
3、查看es集群状态
curl -XGET http://localhost:9200/_cat/health?v
4.新建索引
curl -X PUT localhost:9200/test
{
"acknowledged":true,
"shards_acknowledged":true,
"index":"test-zp"
}
5.删除索引
curl -X DELETE localhost:9200/test
{
"acknowledged":true
}
cluster ,集群名称
status,集群状态 green代表健康;yellow代表分配了所有主分片,但至少缺少一个副本,此时集群数据仍旧完整;red代表部分主分片不可用,可能已经丢失数据。
node.total,代表在线的节点总数量
node.data,代表在线的数据节点的数量
shards, active_shards 存活的分片数量
pri,active_primary_shards 存活的主分片数量 正常情况下 shards的数量是pri的两倍。
relo, relocating_shards 迁移中的分片数量,正常情况为 0
init, initializing_shards 初始化中的分片数量 正常情况为 0
unassign, unassigned_shards 未分配的分片 正常情况为 0
pending_tasks,准备中的任务,任务指迁移分片等 正常情况为 0
max_task_wait_time,任务最长等待时间
active_shards_percent,正常分片百分比 正常情况为 100%