三、elasticsearch增删改查
程序员文章站
2022-07-05 08:05:18
...
一、新建索引
put http://{{host}}:9200/liarbry
二、增加document
- 指定id
put http://{{host}}:9200/liarbry/books/1
{
"title":"spring boot program idea3",
"user":{
"first":"hongwei",
"last":"zhang"
},
"price":300
}
- 不指定id
post http://{{host}}:9200/liarbry/books
{
"title":"spring boot program idea",
"user":{
"first":"hongwei",
"last":"zhang"
},
"price":200
}
三、更新document
- 覆盖更新
这个时候body中有什么字段,最终就会有什么字段
put http://{{host}}:9200/liarbry/books/1
{
"title":"spring boot program idea4",
"user":{
"first":"hongwei",
"last":"zhang"
},
"price":300
}
- 局部更新
doc中可以是已经存在的字段,这个时候就会更新已经存在的字段
如果是不存在的字段,就是添加字段操作
post http://{{host}}:9200/liarbry/books/1/_update
{
"doc":{
"date":"2019-06-28 00:01:01"
}
}
四、删除document
- 删除document
delete http://{{host}}:9200/liarbry/books/1
- 删除type
delete http://{{host}}:9200/liarbry/books
- 删除index
delete http://{{host}}:9200/liarbry
五、查询document
查询是最复杂的,下面只是列出最简单的
- 根据id来查询
get http://{{host}}:9200/liarbry/books/1
- 批量获取
#batch query
GET /_mget
{
"docs":[
{
"_index":"liarbry",
"_type":"books",
"_id":"1",
"_source":["title","price"]
},
{
"_index":"liarbry",
"_type":"books",
"_id":"AWujzBfklrzOujYjNVt4"
}
]
}
#specified index/type
GET /liarbry/books/_mget
{
"docs":[
{"_id":"1"},
{"_id":"AWujzBfklrzOujYjNVt4"}
]
}
#above shorthand
GET /liarbry/books/_mget
{
"ids":["1","AWujzBfklrzOujYjNVt4"]
}
五、批量增删改
- bulk operate scheme
{action:{metadata}}\n
{request body}\n
{action:{metadata}}\n
{request body}\n
- action description
action | description |
---|---|
create | if not exists,create it |
index | if not exists then create it. if exists then cover it |
delete | delete document |
update | partial update |
- example
POST /liarbry/books/_bulk
{"index":{"_id":"2"}}
{"title":"books2","price":10}
{"index":{"_id":"3"}}
{"title":"books3","price":30}
上一篇: ElasticSearch 增删改查
下一篇: 操作系统复习
推荐阅读
-
ASP.NET CORE系列【三】使用Entity Framework Core进行增删改查
-
springboot整合Elasticsearch实现增删改查
-
Java通过JDBC连接数据库的三种方式!!!并对数据库实现增删改查
-
asp.net mvc 三层加EF 登录注册 增删改查
-
abp(net core)+easyui+efcore实现仓储管理系统——ABP WebAPI与EasyUI结合增删改查之三(二十九)
-
hibernate 增改查后对象的三种状态转换
-
python全栈开发自学之路04——通过文件实现三级菜单增删改查
-
Mybatis学习(三)增删改查
-
Mybatis(学习三)--增删改查
-
JDBC基础学习之增删改查(三)