# 创建 索引为megacorp 类型为 employeePUT /megacorp/_create/1{"first_name":"John","last_name":"Smith","age":25,"about":"I love to go rock climbing","interests": ["sports","music" ]}
{"_index":"megacorp","_type":"_doc","_id":"1","_version":1,"_seq_no":0,"_primary_term":1,"found":true,"_source": {"first_name":"John","last_name":"Smith","age":25,"about":"I love to go rock climbing","interests": ["sports","music" ] }}
修改文档
修改文档与创建文档类似,您可以选择PUT 或者POST,参数如下
{index}/_doc/{id}
这里我们将上面创建的文档about字段内添加 !
POST /megacorp/_doc/1{"first_name":"John","last_name":"Smith","age":25,"about":"I love to go rock climbing!","interests": ["sports","music" ]}
PUT /megacorp/_doc/2{"first_name":"Jane","last_name":"Smith","age":32,"about":"I like to collect rock albums","interests": [ "music" ]}PUT /megacorp/_doc/3{"first_name":"Douglas","last_name":"Fir","age":35,"about":"I like to build cabinets","interests": [ "forestry" ]}
我们首先确认在megacorp这个index下有几个对象
GET /megacorp/_search
可以看到,之前的三个资源已经创建成功,这是我们将id为3的删除
DELETE /megacorp/_doc/3
或者我们将整个megacorp下的索引资源进行删除
DELETE /megacorp
这是我们在执行 GET /megacorp/_search,会发现提示404,说明我们想要查询的资源已经不存在了,具体如下
{"error": {"root_cause": [ {"type":"index_not_found_exception","reason":"no such index [megacorp]","resource.type":"index_or_alias","resource.id":"megacorp","index_uuid":"_na_","index":"megacorp" } ],"type":"index_not_found_exception","reason":"no such index [megacorp]","resource.type":"index_or_alias","resource.id":"megacorp","index_uuid":"_na_","index":"megacorp" },"status":404}