常用 API
1.0 版引入
此页面包含热门 OpenSearch 操作的示例请求。
目录
- 使用非默认设置创建索引
- 索引带随机 ID 的文档
- 索引带特定 ID 的文档
- 一次索引多个文档
- 列出所有索引
- 打开或关闭所有匹配模式的索引
- 删除所有匹配模式的索引
- 创建索引别名
- 列出所有别名
- 搜索匹配模式的索引或所有索引
- 获取集群设置,包括默认设置
- 更改磁盘水印(或其他集群设置)
- 获取集群健康状况
- 列出集群中的节点
- 获取节点统计信息
- 获取存储库中的快照
- 拍摄快照
- 恢复快照
使用非默认设置创建索引
PUT my-logs
{
"settings": {
"number_of_shards": 4,
"number_of_replicas": 2
},
"mappings": {
"properties": {
"title": {
"type": "text"
},
"year": {
"type": "integer"
}
}
}
}
索引带随机 ID 的文档
POST my-logs/_doc
{
"title": "Your Name",
"year": "2016"
}
索引带特定 ID 的文档
PUT my-logs/_doc/1
{
"title": "Weathering with You",
"year": "2019"
}
一次索引多个文档
请求体末尾的空行是必需的。如果省略 _id
字段,OpenSearch 会生成一个随机 ID。
POST _bulk
{ "index": { "_index": "my-logs", "_id": "2" } }
{ "title": "The Garden of Words", "year": 2013 }
{ "index" : { "_index": "my-logs", "_id" : "3" } }
{ "title": "5 Centimeters Per Second", "year": 2007 }
列出所有索引
GET _cat/indices?v&expand_wildcards=all
打开或关闭所有匹配模式的索引
POST my-logs*/_open
POST my-logs*/_close
删除所有匹配模式的索引
DELETE my-logs*
创建索引别名
此请求为索引 my-logs-2019-11-13
创建别名 my-logs-today
。
PUT my-logs-2019-11-13/_alias/my-logs-today
列出所有别名
GET _cat/aliases?v
搜索匹配模式的索引或所有索引
GET my-logs/_search?q=test
GET my-logs*/_search?q=test
获取集群设置,包括默认设置
GET _cluster/settings?include_defaults=true
更改磁盘水印(或其他集群设置)
PUT _cluster/settings
{
"transient": {
"cluster.routing.allocation.disk.watermark.low": "80%",
"cluster.routing.allocation.disk.watermark.high": "85%"
}
}
获取集群健康状况
GET _cluster/health
列出集群中的节点
GET _cat/nodes?v
获取节点统计信息
GET _nodes/stats
获取存储库中的快照
GET _snapshot/my-repository/_all
拍摄快照
PUT _snapshot/my-repository/my-snapshot
恢复快照
POST _snapshot/my-repository/my-snapshot/_restore
{
"indices": "-.opendistro_security",
"include_global_state": false
}