Elasticsearch 操作
2018-08-26 17:20:18来源:博客园 阅读 ()
集群健康检查
取得健康状态
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 1535248805 10:00:05 elasticsearch yellow 1 1 1 1 0 0 1 0 - 50.0%
健康状态分类
green:索引的primary shard和replica shard都是active状态的
yellow:索引的primary shard都是active状态的,但是部分replica shard不是active状态,处于不可用的状态、
red:不是所有索引的primary shard都是active状态的,部分索引有数据丢失了
当前处于yellow状态是因为目前只启动了一个es进程,只有一个节点node,这是不安全的。这个节点的primary shard 有分配,但是replica shard 没有节点分配,因此是yellow状态。
快速查看集群有哪些节点
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size yellow open .kibana xSbUffi_SYGYIhPtiMxH5w 1 1 1 0 3.1kb 3.1kb
简单的索引操作
{ "acknowledged": true, "shards_acknowledged": true }
{ "acknowledged": true }
CURD 操作Demo
(1)新增商品:新增文档,建立索引
PUT /ecommerce/product/1 { "name" : "xi jie jing", "desc" : "gaoxiao qing jie", "price" : 30, "producer" : "xijiejing producer", "tags": [ "qingxi", "wuzhi" ] }
{ "_index": "ecommerce", "_type": "product", "_id": "1", "_version": 1, "result": "created", "_shards": { "total": 2, "successful": 1, "failed": 0 }, "created": true }
新增
PUT /ecommerce/product/2 { "name" : "niunai", "desc" : "mengniu niunai", "price" : 25, "producer" : "mengniuniunai producer", "tags": [ "niunai" ] }
返回:
{ "_index": "ecommerce", "_type": "product", "_id": "2", "_version": 1, "result": "created", "_shards": { "total": 2, "successful": 1, "failed": 0 }, "created": true }
GET /ecommerce/product/1
返回:
{ "_index": "ecommerce", "_type": "product", "_id": "1", "_version": 1, "found": true, "_source": { "name": "xi jie jing", "desc": "gaoxiao qing jie", "price": 30, "producer": "xijiejing producer", "tags": [ "qingxi", "wuzhi" ] } }
PUT /ecommerce/product/1 { "name" : "jiaqiangban gaolujie yagao", "desc" : "gaoxiao meibai", "price" : 30, "producer" : "gaolujie producer", "tags": [ "meibai", "fangzhu" ] }
返回:
{ "_index": "ecommerce", "_type": "product", "_id": "1", "_version": 2, "result": "updated", "_shards": { "total": 2, "successful": 1, "failed": 0 }, "created": false }
DELETE /ecommerce/product/1
{ "found": true, "_index": "ecommerce", "_type": "product", "_id": "1", "_version": 3, "result": "deleted", "_shards": { "total": 2, "successful": 1, "failed": 0 } }
{ "took": 12, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 1, "max_score": 1, "hits": [ { "_index": "ecommerce", "_type": "product", "_id": "2", "_score": 1, "_source": { "name": "niunai", "desc": "mengniu niunai", "price": 25, "producer": "mengniuniunai producer", "tags": [ "niunai" ] } } ] } }
字段说明:
GET /ecommerce/product/_search { "query": { "match_all": {} } }
按照价格排序:
GET /ecommerce/product/_search { "query" : { "match" : { "name" : "yagao" } }, "sort": [ { "price": "desc" } ] }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:mybatis架构
下一篇:2019 Java面试题
- 学习Java 8 Stream Api (4) - Stream 终端操作之 collect 2020-06-11
- 数据源管理 | Kafka集群环境搭建,消息存储机制详解 2020-06-11
- Spring Boot 教程 - Elasticsearch 2020-06-09
- Dubbo+Zookeeper集群案例 2020-06-09
- 【从单体架构到分布式架构】(二)请求增多,单点变集群(1) 2020-06-07
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash