当前位置:   article > 正文

Elasticsearch增删改查简单操作_elasticsearchrepository 修改怎么操作

elasticsearchrepository 修改怎么操作

新增文档(自定义文档id) 或者更新整个文档

put /student/_doc/1
{
“std_id”: 1,
“std_name”: “zhao zi long”,
“std_sex”: “man”,
“std_age”: 18,
“create_time”: “2021/05/27 11:37:00”,
“update_time”: “2021/05/27 11:37:00”
}

新增文档(自动生成文档id)

POST /student/_doc
{
“std_id”: 2,
“std_name”: “guan yu”,
“std_sex”: “man”,
“std_age”: 20,
“create_time”: “2021/05/27 11:37:00”,
“update_time”: “2021/05/27 11:37:00”
}

获取文档

GET /student/_doc/1?pretty

检查文档是否存在

HEAD /student/_doc/1

返回文档的一部分

GET /student/_doc/1/_source

删除文档

delete /student/_doc/1

乐观锁更新整个文档

put /student/_doc/1?if_seq_no=47&if_primary_term=1
{
“std_id”: 1,
“std_name”: “zhao zi long”,
“std_sex”: “man”,
“std_age”: 18,
“create_time”: “2021/05/27 11:37:00”,
“update_time”: “2021/05/27 11:37:00”
}
#外部版本号

乐观锁更新整个文档

put /student/_doc/1?version=22&version_type=external
{
“std_id”: 1,
“std_name”: “zhao zi long”,
“std_sex”: “man”,
“std_age”: 18,
“create_time”: “2021/05/27 11:37:00”,
“update_time”: “2021/05/27 11:37:00”
}

文档部分更新

POST /student/_update/1
{
“doc”:{
“std_age”: 29
}
}

使用脚本部分更新文档

POST /student/_update/1
{
“script”: “ctx._source.std_age+=1”
}

获取多个文档

GET /_mget
{
“docs”: [
{
“_index” : “student”,
“_id” : 1
},
{
“_index” : “student”,
“_id” : 2
}
]
}

获取多个文档

GET /student/_mget
{
“docs”: [
{
“_id” : 1
},
{
“_id” : 2
}
]
}

批量操作

POST /_bulk
{“create”:{"_index": “student”, “_id”: “2” }}
{“std_id”: 2,“std_name”: “guan yu”,“std_sex”: “man”,“std_age”: 18,“create_time”: “2021/05/27 11:37:00”,“update_time”: “2021/05/27 11:37:00”}
{“delete”:{"_index": “student”, “_id”: “2” }}
{“index”:{"_index": “student”, “_id”: “3” }}
{“std_id”: 3,“std_name”: “liu bei”,“std_sex”: “man”,“std_age”: 18,“create_time”: “2021/05/27 11:37:00”,“update_time”: “2021/05/27 11:37:00”}
{“update”:{"_index": “student”, “_id”: “3” }}
{“doc”:{“std_age”: 38}}

批量操作同一个index

POST /student/_bulk
{“create”:{"_id": “2” }}
{“std_id”: 2,“std_name”: “guan yu”,“std_sex”: “man”,“std_age”: 18,“create_time”: “2021/05/27 11:37:00”,“update_time”: “2021/05/27 11:37:00”}
{“delete”:{"_id": “2” }}
{“index”:{"_id": “3” }}
{“std_id”: 3,“std_name”: “liu bei”,“std_sex”: “man”,“std_age”: 18,“create_time”: “2021/05/27 11:37:00”,“update_time”: “2021/05/27 11:37:00”}
{“update”:{"_id": “3” }}
{“doc”:{“std_age”: 38}}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/68843
推荐阅读
相关标签
  

闽ICP备14008679号