ES操作看这一篇就够了
程序员文章站
2022-06-04 18:50:25
...
【go封装的操作还是得看作者的】
1、创建空索引
PUT /online
curl -H "Content-Type: application/json" -X PUT --data '{"settings":{"index":{"number_of_shards":2,"number_of_replicas":"0"}}}' 172.17.0.2:9200/user
2、删除索引
DELETE /online
curl -v -X DELETE 172.17.0.2:9200/online
3、插入数据
curl -H "Content-Type: application/json" -X POST --data '{"doc":{}}}' http://localhost:9200/online/table
curl -H "Content-Type: application/json" -X POST --data '{"user_name":"tang","records":{}}' http://172.17.0.2:9200/user/user
4、更新数据
POST /online/table/qqqqqqqqqq 可以直接覆盖
curl -H "Content-Type: application/json" -X POST --data '{"doc":{"bbb":["Bdd1","gg"]}, "detect_noop": false}' 172.17.0.2:9200/user/user/c6d8c084-86ad-440a-8efb-3ad3bd3cc669/_update
curl -H "Content-Type: application/json" -X POST --data '{"script" : "ctx._source.applys.remove(\"3c1f7c0a-be92-4797-abdd-23ff7b0401df\")"}' 172.17.0.2:9200/user/user/40435324-57da-4d75-99e8-6fa69d3ef15f/_update
局部更新
5、删除数据
DELETE /online/table/qqqqqqqqqq
curl -v -X DELETE 172.17.0.2:9200/online/table/5a0443bb-4cbc-4614-9f65-48eecb6d48fc
curl -v -X DELETE 172.17.0.2:9200/user/user/_junxHAB9FugYMT7hGtV
6、搜索数据
GET /online/table/qqqqqqqqqq 单条数据
GET /online/table/_search 全部数据 默认返回10条
GET /online/table/_search?q=name:"新建文档" 关键字搜索
GET /online/table/qqqqqqqqqq?_source=id,name 只返回这两个字段的信息
GET /online/table/qqqqqqqqqq/_source 只返回元数据信息
GET /online/table/qqqqqqqqqq/_source?_source=id,name 只返回这两个字段的元数据信息
curl -v 172.17.0.2:9200/online/table/b05e85ba-d09e-4eee-b119-418d87f534c1
curl -v 172.17.0.2:9200/user/user/40435324-57da-4d75-99e8-6fa69d3ef15f
curl -v 172.17.0.2:9200/user/user/_search
DSL 搜索
POST /online/table/_search
_index = 数据库
_type = 表
_id 与上面两个组合,唯一标识一个文档
是否存在
HEAD /online/table/qqqqqqqqqq 查看响应码
7、批量操作
POST /online/table/_mget
{
"ids":["1001","1003"]
}
局部更新 : /haoke/user/1001/_update https://www.bilibili.com/video/av67957955?p=10
关键字搜索: /haoke/user/_search?q=name:tang
DSL 搜索: /haoke/user/_search POST 请求
{"query":{
"match":{
"age":21
}
}
}
聚合:
上一篇: 他是荒淫无度的昏君,被世人所唾弃,为何孔子为他翻案?
下一篇: Prometheus入门