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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM