1.创建索引
PUT /customer?pretty
GET /_cat/indices?v
返回值:
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open customer 95SQ4TSUT7mWBT7VNHH67A 5 1 0 0 260b 260b
2.插入一条数据
PUT /customer/_doc/1?pretty
{
"name": "John Doe"
}
返回值:
{
"_index" : "customer",
"_type" : "_doc",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
3.删除索引
DELETE /customer?pretty
GET /_cat/indices?v
返回值:
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
4.修改数据,直接输入依据id覆盖
PUT /customer/_doc/1?pretty
{
"name": "John Doe"
}
5.更新文档
(1)修改name字段为“Jane Doe”
POST /customer/_doc/1/_update?pretty
{
"doc": { "name": "Jane Doe" }
}
(2)通过将name字段更改为“Jane Doe”并同时向其添加一个age字段,更新我们以前的文档(ID为1)
POST /customer/_doc/1/_update?pretty
{
"doc": { "name": "Jane Doe", "age": 20 }
}
(3)还可以使用简单的脚本执行更新。这个例子使用一个脚本将年龄增加5
POST /customer/_doc/1/_update?pretty
{
"script" : "ctx._source.age += 5"
}
6.删除文档
删除我们之前的文档,ID为2
DELETE /customer/_doc/2?pretty
7.批量处理
(1)在一个批量操作中调用索引两个文档(ID 1 - John Doe和ID 2 - Jane Doe)
POST /customer/_doc/_bulk?pretty
{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }
(2)更新第一个文档(ID为1),然后在一次批量操作中删除第二个文档(ID为2)
POST /customer/_doc/_bulk?pretty
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}
8、postman批量导入json文件
导入json
网友评论