Elasticsearch 入门: RESTful增删改查

2018-06-14 16:20:34 浏览数 (1)

RESTful API:一般来说增(POST)删(DELETE)改(PUT)查(GET)

增 POST

  • 每个雇员索引一个文档,包含该雇员的所有信息。
  • 该类型位于索引 megacorp 内。
  • 每个文档都将是 employee 类型 。
代码语言:javascript复制
POST /employee/megacrop/
{
  "first_name": "John",
  "last_name": "Smith",
  "age": 25,
  "about": "whatever",
  "interests": ["sports","music"]
}
查 GET
代码语言:javascript复制
GET /megacorp/employee/1
  • 得到结果
代码语言:javascript复制
{
  "_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
  • 得到结果
代码语言:javascript复制
{
  "_index": "megacorp",
  "_type": "employee",
  "_id": "1",
  "_version": 3,
  "result": "deleted",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 8,
  "_primary_term": 1
}
  • 再 GET 确认
代码语言:javascript复制
GET /megacorp/employee/1
  • 得到结果
代码语言:javascript复制
{
  "_index": "megacorp",
  "_type": "employee",
  "_id": "1",
  "found": false
}
es2

0 人点赞