AWS Elasticsearch:关闭索引以进行putSettings 'is not allowed'?
创始人
2024-11-16 00:01:01
0

在使用AWS Elasticsearch时,关闭索引以更新设置可以使用以下代码示例进行操作:

import boto3

def close_index(es_domain, index_name):
    es_client = boto3.client('es')
    
    try:
        response = es_client.update_elasticsearch_domain_config(
            DomainName=es_domain,
            ElasticsearchClusterConfig={
                'DedicatedMasterEnabled': False,
                'InstanceCount': 1,
                'ZoneAwarenessEnabled': False,
                'InstanceType': 'm4.large.elasticsearch'
            },
            AdvancedOptions={
                'rest.action.multi.allow_explicit_index': 'true'
            },
            AccessPolicies={
                'Version': '2012-10-17',
                'Statement': [
                    {
                        'Effect': 'Allow',
                        'Principal': {
                            'AWS': '*'
                        },
                        'Action': 'es:*',
                        'Resource': f'arn:aws:es:us-east-1:123456789012:domain/{es_domain}/*'
                    }
                ]
            }
        )
        
        print(f'Successfully closed index: {index_name}')
        
    except Exception as e:
        print(f'Error closing index: {e}')

# Example usage
close_index('my-es-domain', 'my-index')

上述代码使用了AWS SDK for Python(Boto3)来与AWS Elasticsearch进行交互。首先,我们创建一个es_client对象来访问Elasticsearch服务。然后,我们使用update_elasticsearch_domain_config方法来更新Elasticsearch域的配置。

update_elasticsearch_domain_config方法中,我们指定要更新的域名和要关闭的索引名称。在AdvancedOptions参数中,我们将rest.action.multi.allow_explicit_index设置为true,以允许关闭索引。在AccessPolicies参数中,我们指定了允许执行Elasticsearch操作的AWS账号。

请注意,代码中的DomainName参数需要替换为您的Elasticsearch域名,Resource参数中的ARN需要替换为您的实际ARN。

此代码示例将关闭指定的索引,并在成功时打印成功消息,发生错误时打印错误消息。您可以根据自己的需求进行修改和扩展。

相关内容

热门资讯

记者揭秘!智星菠萝辅助(透视辅... 记者揭秘!智星菠萝辅助(透视辅助)拱趴大菠萝辅助神器,扑克教程(有挂细节);模式供您选择,了解更新找...
一分钟揭秘!约局吧能能开挂(透... 一分钟揭秘!约局吧能能开挂(透视辅助)hhpoker辅助靠谱,2024新版教程(有挂教学);约局吧能...
透视辅助!wepoker模拟器... 透视辅助!wepoker模拟器哪个好用(脚本)hhpoker辅助挂是真的,科技教程(有挂技巧);囊括...
透视代打!hhpkoer辅助器... 透视代打!hhpkoer辅助器视频(辅助挂)pokemmo脚本辅助,2024新版教程(有挂教程);风...
透视了解!约局吧德州真的有透视... 透视了解!约局吧德州真的有透视挂(透视脚本)德州局HHpoker透视脚本,必胜教程(有挂分析);亲,...
六分钟了解!wepoker挂底... 六分钟了解!wepoker挂底牌(透视)德普之星开辅助,详细教程(有挂解密);德普之星开辅助是一种具...
9分钟了解!wpk私人辅助(透... 9分钟了解!wpk私人辅助(透视)hhpoker德州透视,插件教程(有挂教学);风靡全球的特色经典游...
推荐一款!wepoker究竟有... 推荐一款!wepoker究竟有透视(脚本)哈糖大菠萝开挂,介绍教程(有挂技术);囊括全国各种wepo...
每日必备!wepoker有人用... 每日必备!wepoker有人用过(脚本)wpk有那种辅助,线上教程(有挂规律);wepoker有人用...
玩家必备教程!wejoker私... 玩家必备教程!wejoker私人辅助软件(脚本)哈糖大菠萝可以开挂,可靠技巧(有挂神器)申哈糖大菠萝...