简体   繁体   English

在Elasticsearch中为索引重新索引-ELK

[英]Reindexing a index in elasticsearch - ELK

What's the best practise to reindex an elastic search index? 重新编制弹性搜索索引的最佳实践是什么? This post has few steps which involves stopping logstash indexer before reindexing an index but that's not an option for me as its a production server. 这篇文章有几个步骤,涉及在重新索引索引之前停止logstash索引器,但是作为生产服务器,对于我来说这不是一个选择。

I had a problem where there were no *.raw fields in an index, because of missing default mapping template. 我有一个问题,因为缺少默认的映射模板,索引中没有* .raw字段。 I used the mapping template from Elasticsearch found here and configured my ES cluster to use it, but I guess it will only be used when either a new index is created or when I explicitly reindex an existing index. 我使用了从此处找到的Elasticsearch中的映射模板,并配置了我的ES集群以使用它,但是我猜它仅在创建新索引或显式重新索引现有索引时才使用。

Also /_template?pretty resulted back an empty response, but after adding the aforementioned template /_template?pretty reveals a new template, but will the new index that would be created use this new template automatically? /_template?pretty返回空响应,但是在添加了上述模板后, /_template?pretty显示一个新模板,但是要创建的新索引会自动使用此新模板吗? Or do I need to configure ES explicitly asking it to use them? 还是我需要配置ES明确要求它使用ES?

I would really appreciate some help here. 我非常感谢您的帮助。

The best way to do this IMO is to have an alias pointing to your actual index. 执行此IMO的最佳方法是使用别名指向您的实际索引。 ( https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html ), something like my-index-alias pointing to my-actual-index-20170101 https://www.elastic.co/guide/zh-CN/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" } }
    ]
}

When you query (or add stuffs) to your index, you always use the alias name. 当查询(或添加内容)到索引时,始终使用别名。

If you need to reindex, you reindex to another index ( my-actual-index-20170127 by example) and when the reindexing is done, you update the alias to point to the new index. 如果需要重新索引,则可以重新索引到另一个索引(例如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" } }
    ]
}

It'll allow you to reindex an index without changing any code / having any downtime. 它允许您在不更改任何代码/不造成任何停机的情况下为索引重新编制索引。

Now, regarding the actual reindexing problem-- I've been using the elasticsearch-reindex node app with a lot of success ( https://www.npmjs.com/package/elasticsearch-reindex ). 现在,关于实际的重新编制索引问题-我一直在使用elasticsearch-reindex节点应用程序,并获得了很多成功( https://www.npmjs.com/package/elasticsearch-reindex )。

Its usage is easy : 它的用法很简单:

after installing it with npm ( npm install -g elasticsearch-reindex ), you can just run 用npm npm install -g elasticsearch-reindex后( 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

A simple way to reindex your documents(using Kibana Sense) in another index with the new template applied can be: 使用新模板在另一个索引中重新索引文档(使用Kibana Sense)的简单方法是:

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

Another way to do a lot of different actions with Elasticsearch including re-indexing is Curator . 使用Elasticsearch进行许多不同操作(包括重新索引)的另一种方法是Curator

Its latest version is compatible with ES 5.x and 6.x 其最新版本与ES 5.x和6.x兼容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM