<REST Verb> /<Index>/<Type>/<ID>
<REST动词> / <索引> / <类型> / <ID>
#检查群集运行状况
GET /_cat/health?v
#获得群集中的节点列表
GET /_cat/nodes?v
#列出所有索引
GET /_cat/indices?v
#创建索引并查看
PUT /customer?pretty
GET /_cat/indices?v
#指定ID插入数据并查看(如果没有该索引则默认自动创建)
PUT /customer/_doc/1?pretty
{
"name": "John Doe"
}
GET /customer/_doc/1?pretty
#删除索引并查看
DELETE /customer?pretty
GET /_cat/indices?v
#不指定ID插入数据会自动分配ID
POST /customer/_doc?pretty
{
"name": "Jane Doe"
}
#替换文档版本号会递增,若该ID尚未使用则相当于插入数据
GET /customer/_doc/1?pretty
PUT /customer/_doc/1?pretty
{
"name": "John Doe"
}
GET /customer/_doc/1?pretty
PUT /customer/_doc/1?pretty
{
"name": "Jane Doe"
}
GET /customer/_doc/1?pretty
PUT /customer/_doc/2?pretty
{
"name": "Jane Doe"
}
#通过将名称字段更改为“Jane Doe”来更新以前的文档(ID为1)
GET /customer/_doc/1?pretty
POST /customer/_doc/1/_update?pretty
{
"doc": { "name": "Jane Doe" }
}
GET /customer/_doc/1?pretty
#通过将名称字段更改为“Jane Doe”来更新我们以前的文档(ID为1),同时向其添加年龄字段
POST /customer/_doc/1/_update?pretty
{
"doc": { "name": "Jane Doe", "age": 20 }
}
GET /customer/_doc/1?pretty
#使用脚本将年龄增加5
POST /customer/_doc/1/_update?pretty
{
"script" : "ctx._source.age += 5"
}
GET /customer/_doc/1?pretty
#删除ID为2的文档
GET /customer/_doc/2?pretty
DELETE /customer/_doc/2?pretty
GET /customer/_doc/2?pretty
#批处理
GET /customer/_doc/1?pretty
GET /customer/_doc/2?pretty
POST /customer/_doc/_bulk?pretty
{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }
GET /customer/_doc/1?pretty
GET /customer/_doc/2?pretty
POST /customer/_doc/_bulk?pretty
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}
GET /customer/_doc/1?pretty
GET /customer/_doc/2?pretty
#q=*匹配索引中的全部文档
GET /customer/_search?q=*&&pretty
#JSON查询体匹配索引中的全部文档
GET /customer/_search
{
"query": { "match_all": {} }
}
#size指定查询文档大小,若未指定,则默认为10
GET /customer/_search
{
"query": { "match_all": {} },
"size": 1
}
#from参数(基于0)指定从哪个文档索引开始,size参数指定从from参数开始返回多少文档
#这个特性在实现搜索结果分页时非常有用!注意,如果未指定from,则默认为0
GET /customer/_search
{
"query": { "match_all": {} },
"from": 10,
"size": 10
}
#此示例执行match_all并按帐户余额降序对结果进行排序,并返回前10个(默认大小)文档
GET /bank/_search
{
"query": { "match_all": {} },
"sort": { "balance": { "order": "desc" } }
}
es搜索引擎,Kibana语法
最新推荐文章于 2023-02-09 11:22:15 发布