AWS ElasticSearch:如何将策略应用于索引 [英] AWS ElasticSearch: How to apply a policy to an index

查看:102
本文介绍了AWS ElasticSearch:如何将策略应用于索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个AWS ElasticSearch域,并且正在向其中写入记录/文档.现在,我已经在Kibana中创建了索引状态/生命周期管理(ISM/ILM)策略,并且可以在Kibana中将策略应用于索引.我现在想在从处理对索引的写入的Java代码中创建索引(使用高级REST API)时应用该策略.

We have an AWS ElasticSearch domain and are writing records/documents to it. I've now created an Index State/Lifecycle Management (ISM/ILM) policy in Kibana and I can apply the policy to an Index from within Kibana. I now want to apply that policy when the index is created from within our Java code that handles writes to the Index (using the High Level REST API).

我在高级REST API中没有找到专门允许将策略分配给索引的方法,但是我认为我应该能够使用创建索引时使用的RequestOptions对象来执行此操作.该文档非常薄,但是看来我应该基本上可以将一个键/值插入到Index属性中.例如,当我检查手动分配策略的索引时,找到分配策略的以下键.

I have found no methods in the High Level REST API that specifically allow assigning a policy to an index, however I think that I should be able to do it using the RequestOptions object that is used when the Index is created. The documentation is pretty thin, but it seems that I should be able to basically insert a key/value into the Index properties. For example, when I inspect the index where I have manually assigned the policy, find the following keys where the policy is assigned.

"settings" : {
  "index" : {
    "opendistro" : {
      "index_state_management" : {
        "policy_id" : "DefaultLifeCyclePolicy_30DayWarm_180DayDelete"
      }
    },

假设我可以将类似的键插入Index对象似乎是合理的.以下代码似乎应该工作.它的运行没有错误,但是RequestOptions没有任何用处.

It seems reasonable to assume that i can just insert a similar key into the Index object. The following code seems like it should work. It does run without error, but the RequestOptions does nothing useful.

        boolean isExisting = mAwsClient.indices().exists(new GetIndexRequest(indexNameFull), RequestOptions.DEFAULT);
        if (!isExisting) {
            RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
            builder.addHeader("settings.opendistro.index_state_management.policy_id", mIndexStateMgmtPolicy);
            RequestOptions requestOptions = builder.build();

            CreateIndexRequest request = new CreateIndexRequest(indexNameFull);
            request.mapping(mapping, XContentType.JSON);
            CreateIndexResponse createIndexResponse = mAwsClient.indices().create(request, requestOptions);
        }

那么,如何使用Java将ISM/ILM策略分配给索引?

So, how can I assign am ISM/ILM policy to an index using Java?

顺便说一句,我已经研究过创建索引模板,该模板应该在创建索引时自动分配策略,但是OpenDistro Kibana似乎没有该功能.

BTW, I have looked at creating an Index Template, which should assign the policy automatically on index creation, but the OpenDistro Kibana does not seem to have that functionality.

推荐答案

顺便说一句,我看过创建索引模板,该模板应分配给索引创建时自动执行该策略,但是OpenDistro Kibana似乎没有该功能.

BTW, I have looked at creating an Index Template, which should assign the policy automatically on index creation, but the OpenDistro Kibana does not seem to have that functionality.

您可以通过以下方式使用索引模板,以在创建索引时应用ISM策略:

You can use the index template in the following manner to apply ISM policy at index creation:

PUT _template/template_1
{
  "index_patterns": [
    "test-index*"
  ],
  "settings": {
    "index": {
      "opendistro": {
        "index_state_management": {
          "policy_id": "DefaultLifeCyclePolicy_30DayWarm_180DayDelete"
        }
      }
    }
  }
}

对于翻滚指数:

  1. 确保您具有别名:


POST /_aliases
{
    "actions" : [
        { "add" : { "index" : "test-index-000001", "alias" : "test-index" } }
    ]
} 

  1. 模板:


PUT _template/template_1
{
  "index_patterns": [
    "test-index*"
  ],
  "settings": {
    "index": {
      "opendistro": {
        "index_state_management": {
          "policy_id": "DefaultLifeCyclePolicy_30DayWarm_180DayDelete",
          "rollover_alias": "test-index"
        }
      }
    }
  }
}

这篇关于AWS ElasticSearch:如何将策略应用于索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆