2

我们对 elasticsearch 1.7 的映射存在问题。我正在通过创建具有正确映射的新索引来解决问题。我知道,由于我正在创建一个新索引,因此我必须使用现有数据从旧索引重新索引到我刚刚创建的新索引。问题是我用谷歌搜索,找不到从旧到新重新索引的方法。似乎重新索引 API 是在 ES 2.3 中引入的,并且不支持 1.7。

我的问题是如何在修复映射后将我的数据从旧数据重新索引到新数据。或者,在 ES 1.7 中进行映射更改的最佳实践是什么?

  1. https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html对我不起作用,因为我们使用的是旧版本的 ES (1.7)
  2. https://www.elastic.co/blog/chang-mapping-with-zero-downtime 最初沿着这条路走,但被卡住了,需要一种方法将旧的索引重新索引到新的
4

2 回答 2

1

你的用例迟到了,但想把它放在那里给其他人。这是关于如何使用 Logstash 1.5 版重新索引 Elasticsearch 索引同时保持原始数据完整性的出色分步指南:http: //david.pilato.fr/blog/2015/05/20/reindex- elasticsearch-with-logstash/

这是logstash-simple.conf作者创建的:

Input {
  # We read from the "old" cluster
  elasticsearch {
    hosts => [ "localhost" ]
    port => "9200"
    index => "index"
    size => 500
    scroll => "5m"
    docinfo => true
  }
}

filter {
  mutate {
    remove_field => [ "@timestamp", "@version" ]
  }
}

output {
  # We write to the "new" cluster
  elasticsearch {
    host => "localhost"
    port => "9200"
    protocol => "http"
    index => "new_index"
    index_type => "%{[@metadata][_type]}"
    document_id => "%{[@metadata][_id]}"
  }
  # We print dots to see it in action
  stdout {
    codec => "dots"
  }
于 2017-12-22T14:03:24.803 回答
0

有几个选项供您选择:

使用 logstash - 在 logstash 中创建重新索引配置并使用它来重新索引您的文档非常容易。例如:

input {
  elasticsearch {
    hosts => [ "localhost" ]
    port => "9200"
    index => "index1"
    size => 1000
    scroll => "5m"
    docinfo => true
  }
}


output {
  elasticsearch {
    host => "localhost"
    port => "9200"
    protocol => "http"
    index => "index2"
    index_type => "%{[@metadata][_type]}"
    document_id => "%{[@metadata][_id]}"
  }
}

这种方法的问题是它会相对较慢,因为您只有一台机器来执行重新索引过程。

另一种选择,使用这个工具。它会比 logstash 更快,但您必须为所有文档提供分段逻辑以加快处理速度。例如,如果您有一个数值范围为 1 - 100 的数字字段,那么您可以将工具中的查询分段为可能 10 个间隔(1 - 10、11 - 20、... 91 - 100),所以该工具将生成 10 个索引器,它们将并行重新索引您的旧索引。

于 2017-03-25T08:53:23.697 回答