为 lib3 索引添加 两个文档
PUT /lib3/_doc/1
{
"first_name":"daicooper",
"last_name":"liu",
"age":23,
"interests":["music","pingpang"]
}
PUT /lib3/_doc/2
{
"first_name":"curry",
"last_name":"ni",
"age":21,
"interests":["music","sing"]
}
#查看 文档 2 数据
GET /lib3/_doc/2
#更新 文档 2中 integer 类型字段
POST /lib3/_update/2
{
"script":"ctx._source.age +=1"
}
# 更新文档 2 中 string 类型字段
POST /lib3/_update/2
{
"script":"ctx._source.first_name +='bing'"
}
# 更新文档 2 中 数组类型字段,向数组中添加一个内容
POST /lib3/_update/2
{
"script":{
"source":"ctx._source.interests.add(params.tag)",
"params":{
"tag":"football"
}
}
}
# 更新文档 2 中 数组类型字段,向数组中删除一个内容
POST /lib3/_update/2
{
"script":{
"source":"ctx._source.interests.remove(ctx._source.interests.indexOf(params.tag))",
"params": {
"tag":"sing"
}
}
}
# 通过条件判断,执行是否删除文档 2
POST /lib3/_update/2
{
"script":{
"source":"ctx.op=ctx._source.age==params.count?'delete':'none'",
"params":{
"count":22
}
}
}
#如果文档不存在,则进行初始化,如果存在则进行script操作。
GET /lib3/_update/2
{
"script":"ctx._source.age +=1",
"upsert":{
"first_name":"curry",
"last_name":"ni",
"age":21,
"interests":["sing"]
}
}