首页 > IT基础架构 > > ElasticSearch基本实操(2)
#修改文档原理 - PUT方式
发生并发冲突的可能性比较大
发生并发冲突可能性降低
查询出document然后使用用户提交过来的数据更新到document中, 已有的document被标记为deleted创建一个新的document。
post方式比put方式网络数据传输的次数要少,从而提高了性能post方式从查询文档到修改文档再到 创建新的文档都是在es内部实现的
GET /lib/user/_searchPUT /lib/user/4
{
"first_name":"Jane",
"last_name":"Lucy",
"age":28,
"about":"I like to collect rock albums",
"interests":["music"]
}POST /lib/user/4/_update
{
"doc":{
"age":29
}
}DELETE /lib/user/4POST /lib/user/4/_update
{
"script": "ctx._source.age+=1"
}POST /lib/user/4/_update
{
"script": "ctx._source.last_name+='Chan'"
}POST /lib/user/4/_update
{
"script": {"source":"ctx._source.interests.add(params.tag)","params": {"tag":"picture"}}
}POST /lib/user/4/_update
{
"script": {"source":"ctx._source.interests.remove(ctx._source.interests.indexOf(params.tag))","params": {"tag":"picture"}}
}POST /lib/user/4/_update
{
"script": {
"source":"ctx.op=ctx._source.age==params.count?'delete':'none'",
"params": {
"count":30
}
}
}POST /lib/user/4/_update
{
"script": "ctx._source.age+=1",
"upsert": {
"first_name":"Jane",
"last_name":"Lucy",
"age":20,
"about":"I like to collect rock albums",
"interests":[
"music"
]
}
}{
"took": 0, #耗时
"timed_out": false, #是否超时
"_shards": { #分片信息
"total": 3,
"successful": 3,
"skipped": 0,
"failed": 0
}GET _search
GET /_all/_searchGET /lib/_search
GET /lib/user/_searchGET /lib,lib3/_searchGET /*3,*4/_searchGET /lib,lib3/user,items/_search
GET /_all/user,items/_search来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/31509949/viewspace-3140563/ ,如需转载,请注明出处,否则将追究法律责任。