RESTful API:一般來說增(POST)刪(DELETE)改(PUT)查(GET)
增 POST
- 每個雇員索引一個文檔灿意,包含該雇員的所有信息。
- 該類型位于索引
megacorp
內(nèi)。- 每個文檔都將是
employee
類型 历葛。
POST /employee/megacrop/
{
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "whatever",
"interests": ["sports","music"]
}
查 GET
GET /megacorp/employee/1
- 得到結(jié)果
{
"_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
PUT /employee/megacrop/1
{
"first_name": "Update",
"last_name": "Smith",
"age": 52,
"about": "whatever",
"interests": ["sports","music"]
}
刪 DELETE
DELETE /megacorp/employee/1
- 得到結(jié)果
{
"_index": "megacorp",
"_type": "employee",
"_id": "1",
"_version": 3,
"result": "deleted",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 8,
"_primary_term": 1
}
- 再 GET 確認(rèn)
GET /megacorp/employee/1
- 得到結(jié)果
{
"_index": "megacorp",
"_type": "employee",
"_id": "1",
"found": false
}