Elasticsearch-cluster health check, document CRUD (study notes)

1. Check the cluster health status

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
1587351378 22:56:18  elasticsearch yellow          1         1      1   1    0    0        1             0                  -                 50.0%

2. Check which indexes are in the cluster

GET _cat/indices?v
#返回值
health status index   uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   .kibana X0UjM7wrRtyj2rgHlbccTg   1   1          1            0      3.1kb          3.1kb

3. Create an index

PUT /test_index?pretty (test_index为要创建的索引名称)
#返回值
{
  "acknowledged": true,
  "shards_acknowledged": true
}

4. Delete the index

DELETE /test_index?pretty (test_index为要删除索引的名称)
#返回值
{
  "acknowledged": true
}

5. New documents

# PUT /index/type/id
PUT /ecommerce/product/1
{
  "name":"gaolujie yagao",
  "desc":"gaoxiao meibai",
  "price":30,
  "producer":"gaolujie producer",
  "tags":["meibai","fangzhu"]
}
#返回值
{
  "_index": "ecommerce",
  "_type": "product",
  "_id": "1",
  "_version": 1,
  "result": "created",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "created": true
}

6. Retrieve documents

#GET /index/type/id
GET /ecommerce/product/1
#返回值
{
  "_index": "ecommerce",
  "_type": "product",
  "_id": "1",
  "_version": 1,
  "found": true,
  "_source": {
    "name": "gaolujie yagao",
    "desc": "gaoxiao meibai",
    "price": 30,
    "producer": "gaolujie producer",
    "tags": [
      "meibai",
      "fangzhu"
    ]
  }
}

7. Modify the document-replace the document (you must bring all the fields to modify the document, if the field is not complete, the previous data will be overwritten)

#PUT /index/type/id
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
}

8. Modify the document-update the document

#POST /index/type/id/_update
POST /ecommerce/product/1/_update
{
  "doc":{
    "name":"gaoujie yagao"    #只修改name字段
  }
}
#返回值
{
  "_index": "ecommerce",
  "_type": "product",
  "_id": "1",
  "_version": 3,
  "result": "updated",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  }
}

9, delete documents

#DELETE /index/type/id
DELETE /ecommerce/product/1?pretty
#返回值
{
  "found": true,
  "_index": "ecommerce",
  "_type": "product",
  "_id": "1",
  "_version": 4,
  "result": "deleted",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  }
}

 

Guess you like

Origin blog.csdn.net/Micheal_yang0319/article/details/105631950