在 elasticsearch 中重新索引索引 - ELK

Reindexing a index in elasticsearch - ELK

重建弹性搜索索引的最佳做法是什么? This post 有几个步骤涉及在重新索引索引之前停止 logstash 索引器,但这对我来说不是一个选项,因为它是一个生产服务器。

由于缺少默认映射模板,我遇到了索引中没有 *.raw 字段的问题。我使用了 Elasticsearch 中的映射模板 here 并将我的 ES 集群配置为使用它,但我想它只会在创建新索引或显式重新索引现有索引时使用。

同样/_template?pretty返回了一个空响应,但是在添加上述模板后/_template?pretty显示了一个新模板,但是创建的新索引会自动使用这个新模板吗?或者我是否需要配置 ES 明确要求它使用它们?

非常感谢您的帮助。

执行此 IMO 的最佳方法是使用别名指向您的实际索引。 (https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html),类似于 my-index-alias 指向 my-actual-index-20170101

POST /_aliases
{
    "actions" : [
        { "add" : { "index" : "my-actual-index-20170101", "alias" : "my-index-alias" } }
    ]
}

当您查询(或添加内容)到您的索引时,您总是使用别名。

如果需要重建索引,则重建索引到另一个索引(例如 my-actual-index-20170127),重建索引完成后,更新别名以指向新索引。

POST /_aliases
{
    "actions" : [
        { "remove" : { "index" : "my-actual-index-20170101", "alias" : "my-index-alias" } },
        { "add" : { "index" : "my-actual-index-20170127", "alias" : "my-index-alias" } }
    ]
}

它允许您在不更改任何代码/没有任何停机时间的情况下重新索引索引。

现在,关于实际的重建索引问题——我一直在使用 elasticsearch-reindex 节点应用程序并取得了很大的成功 (https://www.npmjs.com/package/elasticsearch-reindex)。

它的用法很简单:

用 npm ( npm install -g elasticsearch-reindex) 安装后,你可以 运行

elasticsearch-reindex -f http://localhost:9200/my-actual-index-20170101/{type of documents} -t http://localhost:9200/my-actual-index-20170127

使用新模板在另一个索引中重新索引您的文档(使用 Kibana Sense)的简单方法可以是:

POST /_reindex
{
  "source": {
    "index": "source-index"
  },
  "dest": {
    "index": "dest-index"
  }
}

另一种使用 Elasticsearch 执行许多不同操作(包括重新索引)的方法是 Curator

其最新的version兼容ES5.x和6.x