一、ES数据的操作
1.创建索引
PUT /<index>
PUT /test2
PUT test2
[root@redis01 ~]
2.插入数据
PUT /<index>/_doc/<_id>
POST /<index>/_doc/
PUT /<index>/_create/<_id>
POST /<index>/_create/<_id>
<index>:索引名称,如果索引不存在,会自动创建
_doc:默认类型
<_id>:数据的唯一标识符
1)使用自定义的ID插入数据
PUT test/_doc/1
{
"name":"lhd",
"age":"18"
}
2)使用随机ID插入数据
POST test/_doc/
{
"name":"banzhang",
"age":"18"
}
3)添加字段指定id(一般企业使用)
POST test/_doc/
{
"id":"2",
"name":"banzhang",
"age":"18"
}
3.查询数据
1)简单查询
GET /_all
GET /_all/_search
GET /student
GET /student/_search
GET /student/user/2
2)条件查询
GET /test/_search
{
"query": {
"term": {
"age": {
"value": "18"
}
}
}
}
GET /test/_search
{
"query": {
"term": {
"age": "18"
}
}
}
GET /test/_search
{
"query": {
"bool": {
"must": [
{"term": {
"name": {
"value": "lhd"
}
}}
]
}
}
}
term也可以写match,term搜索时不进行分词用于精确查找,match搜索时会进行分词用于全文检索
3)多条件查询
;
GET /test/_search
{
"query": {
"bool": {
"must": [
{"term": {
"name": {
"value": "lhd"
}
}},
{
"term": {
"age": {
"value": "18"
}
}
}
]
}
}
}
GET /test/_search
{
"query": {
"bool": {
"should": [
{"term": {
"name": {
"value": "lhd"
}
}},
{"term": {
"age": {
"value": "18"
}
}}
]
}
}
}
GET /test/_search
{
"query": {
"bool": {
"must": [
{"term": {
"age": {
"value": "18"
}
}},
{"term": {
"id": {
"value": "2"
}
}},
{"bool": {
"should": [
{"term": {
"name": {
"value": "banzhang"
}
}},
{"term": {
"sex": {
"value": "man"
}
}}
]
}}
]
}
}
}
GET /test/_search
{
"query": {
"bool": {
"must": [
{
"range": {
"age": {
"gt": "20",
"lt": "100"
}
}
}
]
}
}
}
4.修改数据
PUT /test/_doc/fsi5JXIBYdi0LYkVXQhV
{
"name":"qiudao",
"age":"78",
"id":"3",
"sex":"man"
}
POST /test/_doc/fsi5JXIBYdi0LYkVXQhV
{
"name":"qiudao",
"age":"78",
"id":"3",
"sex":"man"
}
5.删除数据
DELETE /test/_doc/cchuJXIBYdi0LYkVpQgS
DELETE /teacher
二、集群

1.集群名词
1)集群健康状态
1.绿色:所有的数据都完整,并且副本数量正常
2.黄色:所有的数据都完整,但是有索引的副本有问题
3.红色:数据都不完整
2)节点类型
1.主节点:负责调度数据分配数据(主节点也是数据节点)
2.数据节点:负责处理分配到自己的数据
3)数据分片
1.主分片:实际存储数据,负责读写
2.副本分片:主分片的备份
2.搭建集群
1)时间同步
2)安装java环境
3)安装ES
4)配置ES
5)配置启动文件
6)启动ES
7)查看HEAD页面插件查看集群状态
三、集群相关事项
1.集群介绍
1.集群中的数据,不论在哪一台操作,都可以使用插件看到所有数据
2.es-head可以连接集群内任何一台机器
3.数据会自动调度到多个分片
4.如果主分片所在的节点坏掉了,副本分片会自动升为主分片
5.如果主节点坏掉了,数据节点会自动升为主节点
2.注意事项
discovery.zen.ping.unicast.hosts: ["10.0.0.91", "10.0.0.94"]
discovery.zen.ping.unicast.hosts: ["10.0.0.91", "10.0.0.93"]
discovery.zen.minimum_master_nodes: 2
五个分片,会保存在多个节点上,当停掉一台机器,集群状态会先变黄在变绿,所以监控不要以集群状态颜色判断
1.紫色:数据正在迁移
2.黄色:数据在复制
1.如果没有副本,则一台都不能坏
2.一个副本的时候,最多可以坏两台,但是只能一台一台坏
3.两个副本的时候,可以随便坏两台
1.索引一旦创建,分片数就不能修改了
2.副本数可以按照节点数量修改
3.查看集群信息命令
1.查看主节点
[root@redis01 ~]
2.查看所有节点
GET /_cat/nodes
3.查看所有索引
[root@redis01 ~]
4.查看集群状态
GET /_cat/health