码迷,mamicode.com
首页 > 其他好文 > 详细

ES 常用语句增删改查

时间:2021-04-20 14:54:42      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:apc   stat   sha   增删改查   queue   node   waiting   查看   创建索引   

  • 快速查看ES集群状态
GET _cluster/health

{
  "cluster_name": "elasticsearch",
  "status": "yellow",
  "timed_out": false,
  "number_of_nodes": 1,
  "number_of_data_nodes": 1,
  "active_primary_shards": 16,
  "active_shards": 16,
  "relocating_shards": 0,
  "initializing_shards": 0,
  "unassigned_shards": 16,
  "delayed_unassigned_shards": 0,
  "number_of_pending_tasks": 0,
  "number_of_in_flight_fetch": 0,
  "task_max_waiting_in_queue_millis": 0,
  "active_shards_percent_as_number": 50
}
  • 快速查看ES集群的索引信息
GET _cat/indices?v

health status index      uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   test_type  ZTEhg0JqQiC3rn_afvle5Q   5   1          1            0      4.1kb          4.1kb
yellow open   test_index C-03qY6HRWCuCVPvNgRD2w   5   1          2            0      7.2kb          7.2kb
yellow open   ecommerce  84jwaWkVSDKtBHVfGOn8TQ   5   1          2            0     10.2kb         10.2kb
yellow open   .kibana    XsGtygBSQb-MNkbAPCbI9Q   1   1          1            0      3.1kb          3.1kb
  • 创建索引
PUT /test_index

创建完成后,再执行 GET _cat/indices?v 就能看到创建的 /test_index 索引了
  • 删除索引
DELETE /test_index

删除完成后,再执行 GET _cat/indices?v 就看不到已经删除的 /test_index 索引了
  • 创建文档
PUT /index/type/id
{
	json数据
}

PUT /ecommerce/product/100
{
    "name":"yunnanbaiyao",
    "desc":"laji",
    "price":40,
    "producer":"yunnanyaoshi",
    "tags":["haha","heihei"]
}
  • 替换文档,必须带上所有field,要不然没有带的field更新后就没有值了
PUT /index/type/id
{
	json数据
}

PUT /ecommerce/product/100
{
    "name":"plus yunnanbaiyao",
    "desc":"laji",
    "price":40,
    "producer":"yunnanyaoshi",
    "tags":["haha","heihei"]
}
  • 更新文档
POST /index/type/id/_update
{
	"doc":{json数据}
}

POST /ecommerce/product/100/_update
{
  "doc": {"name":"hahahhaha"}
}
  • 查询文档
GET /index/type/id

GET /ecommerce/product/100

执行该命令,就能看到我们刚才通过PUT创建的文档了
  • 删除文档
DELETE /index/type/id

DELETE /ecommerce/product/100

ES 常用语句增删改查

标签:apc   stat   sha   增删改查   queue   node   waiting   查看   创建索引   

原文地址:https://www.cnblogs.com/rocker-pg/p/14673031.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!