1、查看集群健康状态
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、查看集群中有哪些索引
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、创建索引
PUT /test_index?pretty (test_index为要创建的索引名称)
#返回值
{
"acknowledged": true,
"shards_acknowledged": true
}
4、删除索引
DELETE /test_index?pretty (test_index为要删除索引的名称)
#返回值
{
"acknowledged": true
}
5、新增文档
# 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、检索文档
#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、修改文档--替换文档(必须带上所有的field才能进行修改文档,如果field不全将会覆盖之前的数据)
#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、修改文档--更新文档
#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 /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
}
}