【问题标题】:Reindexing in Elasticsearch 1.7Elasticsearch 1.7 中的重新索引
【发布时间】:2017-03-24 20:33:28
【问题描述】:

我们的 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/changing-mapping-with-zero-downtime 最初沿着这条路走,但被卡住了,需要一种方法将旧的索引重新索引到新的

【问题讨论】:

  • 升级 Elasticsearch 可能是一项不错的投资。 5.x 支持远程重新索引,因此您可以从 1.7 中提取数据。否则你就是在鞭打一匹死马,任何投资(如自定义重新索引策略)都几乎是浪费。
  • 并非总是可能的。我们在 Elastic 之上使用了一些东西,这将我们锁定在 Elastic v1 上,所以这个问题的答案非常有用。

标签: elasticsearch elasticsearch-mapping


【解决方案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"
  }

【讨论】:

    【解决方案2】:

    有几个选项供您选择:

    使用 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]}"
      }
    }
    

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-25
      相关资源
      最近更新 更多