06_快速入门案例实战之电商网站商品管理:集群健康检查,文档CRUD

  1. document数据格式
  2. 电商网站商品管理案例:背景介绍
  3. 简单的集群管理
  4. 商品的CRUD操作(document CRUD

(3) 集群的管理

1.快速检查集群的健康状态:

cat api 可以查看es中各种各样的数据
GET /_cat/health?v

复制代码
epoch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1488006741 15:12:21  elasticsearch yellow          1         1      1   1    0    0        1             0                  -                 50.0%

epoch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1488007113 15:18:33  elasticsearch green           2         2      2   1    0    0        0             0                  -                100.0%

epoch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1488007216 15:20:16  elasticsearch yellow          1         1      1   1    0    0        1             0                  -                 50.0%

如何快速了解集群的健康状况?green、yellow、red?

green: 每个索引的primary shard和replica shard都是active状态

yellow: 每个索引的primary shard都是active状态, 但是部分的replica shard不是active状态, 处于不用状态

red:不是所有索引的primary shard都是active状态的,部分索引有数据丢失了

为什么现在会处于一个yellow状态?

我们现在就一个笔记本电脑,就启动了一个es进程,相当于就只有一个node。现在es中有一个index,就是kibana自己内置建立的index。由于默认的配置是给每个index分配5个primary shard和5个replica shard,而且primary shard和replica shard不能在同一台机器上(为了容错)。现在kibana自己建立的index是1个primary shard和1个replica shard。当前就一个node,所以只有1个primary shard被分配了和启动了,但是一个replica shard没有第二台机器去启动。

做一个小实验:此时只要启动第二个es进程,就会在es集群中有2个node,然后那1个replica shard就会自动分配过去,然后cluster status就会变成green状态。

新增数据

json 复制代码
PUT /ecommerce/product/1
{
    "name" : "gaolujie yagao",
    "desc" :  "gaoxiao meibai",
    "price" :  30,
    "producer" :      "gaolujie producer",
    "tags": [ "meibai", "fangzhu" ]
}

PUT /ecommerce/product/2
{
    "name" : "jiajieshi yagao",
    "desc" :  "youxiao fangzhu",
    "price" :  25,
    "producer" :      "jiajieshi producer",
    "tags": [ "fangzhu" ]
}

1、上机动手实战演练基于_version进行乐观锁并发控制

json 复制代码
PUT /test_index/test_type/7?version=1 
{
  "test_field": "test client 1"
}

部分更新:

json 复制代码
GET /ecommerce/_doc/2
如果根据这样查询不到,可以考虑GET /ecommerce/_doc/2?routing=xx,因为可能你设置了自己的分片键

POST /ecommerce/_update/2
{
    "doc":{
      "price" :  26
    }
}
相关推荐
分布式存储与RustFS13 小时前
群晖 NAS 被 C3RB3R 锁了:本地备份一起被加密,RustFS 对象锁为什么删不掉
运维·云原生·开源·对象存储·分布式存储·s3·性能基准
真好啊又活了一天13 小时前
服务器和虚机配置IPV6
运维·服务器·github
zixu_star13 小时前
定时任务是什么?从日常自动化到 AI 应用,软件如何自动执行任务?
运维·人工智能·自动化
AR-26710-13 小时前
Linux Day33——定时任务+lvm
linux·运维
润滑卫士14 小时前
液压系统工作粘度窗口等级选型:泵允许粘度范围与油温-粘度匹配计算
运维
每月一号准时摆烂17 小时前
服务器运维笔记(一)——使用shell编写实时查看BMC功率的脚本
运维·服务器·笔记
时间售卖铺18 小时前
Chrony与SSH实战:精准时间同步与安全远程登录
运维·安全·云原生·ssh
微订校园外卖系统18 小时前
校园代取快递系统选型:现成系统与定制开发的技术核对项
大数据·运维·人工智能·外卖系统·本地生活·微订
QXWZ_IA18 小时前
管道GIS测绘如何实现自动化成图:三种成图方式怎么选
运维·人工智能·安全·自动化
一条破秋裤18 小时前
【1112】Linux中断【整理】
linux·运维·服务器