InvokeEsRequest - 代理访问ES

更新时间:
复制 MD 格式

使用已登记的托管凭证代理访问 ES 原生 API,可访问范围由该凭证在 ES 侧的权限决定。另外,通过子账号以及托管凭证访问此接口时调用方除需具备本接口权限外,还需对所使用的凭证具备 elasticsearch:UseCredential 权限。

接口说明

子账号授权可参考如下示例,注意替换区域,账号等信息。

{
    "Version": "1",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "elasticsearch:InvokeEsRequest",
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": "elasticsearch:UseCredential",
            "Resource": "acs:elasticsearch:{#regionId}:{#accountId}:instances/{#instanceId}/credentials/{#credentialId}"
        }
    ]
}

调试

您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。

调试

授权信息

下表是API对应的授权信息,可以在RAM权限策略语句的Action元素中使用,用来给RAM用户或RAM角色授予调用此API的权限。具体说明如下:

  • 操作:是指具体的权限点。

  • 访问级别:是指每个操作的访问级别,取值为写入(Write)、读取(Read)或列出(List)。

  • 资源类型:是指操作中支持授权的资源类型。具体说明如下:

    • 对于必选的资源类型,用前面加 * 表示。

    • 对于不支持资源级授权的操作,用全部资源表示。

  • 条件关键字:是指云产品自身定义的条件关键字。

  • 关联操作:是指成功执行操作所需要的其他权限。操作者必须同时具备关联操作的权限,操作才能成功。

操作

访问级别

资源类型

条件关键字

关联操作

elasticsearch:InvokeEsRequest

none

*Instance

acs:elasticsearch:{#regionId}:{#accountId}:instances/{#instancesId}

无 无

请求语法

POST /openapi/instances/{instanceId}/es-request HTTP/1.1

路径参数

名称

类型

必填

描述

示例值

instanceId

string

是

实例 ID。

es-cn-n6w1o1x0w001c****

请求参数

名称

类型

必填

描述

示例值

path

string

是

要访问的 ES 路径,必填;开头的 / 可省略。

_cat/indices?format=json

method

string

否

访问 ES 时使用的 HTTP 方法,默认 GET。

GET

credentialId

string

否

指定使用的凭证 ID,不传则使用该实例的默认凭证。

cred-7k2mq9xr4vbn

body

string

否

透传给 ES 的请求体,按目标 ES 接口的要求填写;GET 等无请求体的调用可不传。

{"query":{"match_all":{}}}

system

boolean

否

是否使用 aliyun es 系统凭证。默认 false。

false

关于快照请求参考:

具体请求体含义可以参考 elasticsearch 官方文档

查看快照策略

POST /openapi/instances/es-cn-xxx/es-request?path=/_slm/policy&method=GET&system=true

创建自动备份策略

POST /openapi/instances/es-cn-xxx/es-request?path=/_slm/policy/snapshot_test&method=PUT&system=true

body 示例
{
    "schedule": "0 00 04 * * ?",
    "name": "<snapshot_test-{now{yyyyMMddHHmmss}}>",
    "repository": "backupnew",
    "config": {
        "indices": [
            "*",
            "-.monitoring*",
            "-.security*",
            "-.kibana*",
            "-.internal.alerts*",
            "-.alerts*",
            "-.ds*",
            "-.ds-ilm-history-*",
            "-.slo-*"
        ],
        "ignore_unavailable": true,
        "include_global_state": false
    },
    "retention": {
        "expire_after": "7d"
    }
}

手动备份

POST /openapi/instances/es-cn-xxx/es-request?path=/_snapshot/snapshot_test/manual_20260924_1***3_u81b&method=PUT&system=true 

body 示例

{
    "indices": [
        "test_snapshot_index"
    ],
    "ignore_unavailable": true,
    "include_global_state": false
}

快照恢复

POST /openapi/instances/es-cn-xxx/es-request?path=/_snapshot/snapshot_test/manual_20260924_15***_u81b/_restore&method=POST&system=true

body 示例

{
    "indices": "test_snapshot_index",
    "ignore_unavailable": true,
    "include_global_state": false,
    "partial": false,
    "rename_pattern": "(.+)",
    "rename_replacement": "restore1_$1"
}

返回参数

名称

类型

描述

示例值

object

Schema of Response

RequestId

string

Id of the request

8E5A2C41-D96B-4308-AF72-5C0B14E6****

Result

any

ES 原样返回的响应内容,结构由所调用的 ES 接口决定。

{"esResult":{"took":5,"timed_out":false,"hits":{"total":{"value":1,"relation":"eq"},"max_score":1.0,"hits":[{"_index":"my-index","_id":"1","_score":1.0,"_source":{"title":"无线蓝牙耳机"}}]}}}

响应体示例

查看快照仓库

POST /openapi/instances/es-cn-xxx/es-request?path=/_snapshot&method=GET&system=true

{
		"RequestId":"01A0D256-6C5D-1ECE-****B0B4A9CE92A0",
		"Result":{
			"esResult":{
				"snapshot_test":{
					"settings":{
						"bucket":"elasticsearch-test-***",
						"chunk_size":"500mb",
						"endpoint":"http://oss-cn-hangzhou-internal.aliyuncs.com",
						"compress":"true",
						"base_path":"snapshots"
					},
					"type":"oss"
				},
				"aliyun_auto_snapshot":{
					"settings":{
						"endpoint":"http://oss-cn-hangzhou-internal.aliyuncs.com",
						"compress":"true",
						"base_path":"813996-1330710960327595/es-cn-4b84z1c***"
					},
					"type":"oss"
				}
			}
		}
	}

示例

正常返回示例

JSON格式

{
  "RequestId": "8E5A2C41-D96B-4308-AF72-5C0B14E6****",
  "Result": "{\"esResult\":{\"took\":5,\"timed_out\":false,\"hits\":{\"total\":{\"value\":1,\"relation\":\"eq\"},\"max_score\":1.0,\"hits\":[{\"_index\":\"my-index\",\"_id\":\"1\",\"_score\":1.0,\"_source\":{\"title\":\"无线蓝牙耳机\"}}]}}}"
}

错误码

访问错误中心查看更多错误码。

变更历史

更多信息,参考变更详情。