浏览器:127.0.0.1:5601 找到Dev Tools
1.集群运行状况检查
GET /_cat/health?v
2.获取集群中的节点列表
GET /_cat/nodes?v
3.列出所有索引
GET /_cat/indices?v
index索引操作
1.1 新建 Index,可以直接向 Elastic服务器发出PUT请求
PUT /goods
创建了一个goods的Index
服务器返回结果:
{
"acknowledged" : true, #表示成功
"shards_acknowledged" : true,
"index" : "goods"
}
命名规则:
仅小写
不能包括\ / * ? " < > | ``(空格字符) , #
7.0之前的索引可能包含冒号: ,但已过时,并且在7.0+中不支持
不能以 - _ + 开始
不能为.或..
不能超过255个字节
1.2 删除索引
delete请求 删除index
DELETE /goods
1.3 创建文档
1.3.1 手动指定id, body必填
PUT /book/_doc/1
{
"name":"书名",
"desc":"简介",
"studymodel":"201201",
"price": "13.8",
"time": "2024-01-02 12:23:00",
"pic":"/ugc/aa.png",
"tags":["boots", "dev"]
}
返回结果:
1.3.2 查看文档
GET /book/_doc/1
返回结果:
{
"_index": "book",
"_id": "1",
"_version": 1,
"_seq_no": 7,
"_primary_term": 1,
"found": true,
"_source": {
"name": "书名",
"desc": "简介1",
"studymodel": "201201",
"price": "13.8",
"time": "2024-01-02 12:23:00",
"pic": "/ugc/aa.png",
"tags": [
"boots",
"dev"
]
}
}
1.3.3 更新文档
方式1:全局更新
PUT /book/_doc/1
{
"name":"书名",
"desc":"简介1",
"studymodel":"201201",
"price": "13.8",
"time": "2024-01-02 12:23:00",
"pic":"/ugc/aa.png",
"tags":["boots", "dev"]
}
方式2:指定字段更新
POST /book/_update/1
{
"doc": {
"desc":"简介1"
}
}
1.4 删除
DELETE /book/_doc/1
1.5 自动生成id,自动id特点:长度为20个字符,URL安全,base64编码,GUID,分布式生成不冲突.
POST /test_file/_doc
{
"test_field": "test"
}
返回结果:
{
"_index": "test_file",
"_id": "UAaMUY4BHZmdkzBcIILZ",
"_version": 1,
"_seq_no": 1,
"_primary_term": 1,
"found": true,
"_source": {
"test_field": "test"
}
}
1.6 _source 字段:插入数据时的所有字段和值。在get获取数据时,会在_source字段中返回原数据
1.6.1 返回制定字段
查询指定字段 类似select name,age from
GET /book/_doc/1?_source_includes=name,price
返回结果:
{
"_index": "book",
"_id": "1",
"_version": 1,
"_seq_no": 7,
"_primary_term": 1,
"found": true,
"_source": {
"name": "书名",
"price": "13.8"
}
}
标签:index,name,doc,基础,source,Elasticsearch7,book,文档,id
From: https://www.cnblogs.com/l-zl/p/18081420