RESTful API:一般来说增(POST)删(DELETE)改(PUT)查(GET)
增 POST
- 每个雇员索引一个文档,包含该雇员的所有信息。
- 该类型位于索引
megacorp
内。 - 每个文档都将是
employee
类型 。
POST /employee/megacrop/
{
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "whatever",
"interests": ["sports","music"]
}
查 GET
代码语言:javascript复制GET /megacorp/employee/1
- 得到结果
{
"_index": "megacorp",
"_type": "employee",
"_id": "1",
"_version": 2,
"found": true,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "whatever",
"interests": [
"sports",
"music"
]
}
}
改 PUT
代码语言:javascript复制PUT /employee/megacrop/1
{
"first_name": "Update",
"last_name": "Smith",
"age": 52,
"about": "whatever",
"interests": ["sports","music"]
}
删 DELETE
代码语言:javascript复制DELETE /megacorp/employee/1
- 得到结果
{
"_index": "megacorp",
"_type": "employee",
"_id": "1",
"_version": 3,
"result": "deleted",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 8,
"_primary_term": 1
}
- 再 GET 确认
GET /megacorp/employee/1
- 得到结果
{
"_index": "megacorp",
"_type": "employee",
"_id": "1",
"found": false
}