ES 常用语句增删改查

  • 快速查看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
上一篇:APP弱网测试——笔记


下一篇:Unity-图片压缩格式