【问题标题】:Tire create index using custom name without tire:import使用不带轮胎的自定义名称创建轮胎索引:导入
【发布时间】:2016-03-09 15:28:40
【问题描述】:

看这个答案,Update ElasticSearch mapping in production (Tire),导入新索引名称的主要方法是使用 rake

我正在使用 mysqlriver 导入我的数据(有很多,我喜欢控件)。当我第一次使用轮胎设置加载我的 ruby​​ 模型时,它会自动创建一个索引。如何更改它使用的索引名称?

  class Tag
    include Tire::Model::Search
    mapping do 
      indexes :id, :index => :not_analyzed
      indexes :name, :analyzer => 'snowball'
    end

    after_destroy { self.index.remove(self) rescue nil }
    after_save { reindex_dirty %w(name deleted) }
  end

我的目标是让它创建一个名为“tag_version_1”的索引,这样我就可以创建一个别名并进行零停机索引更改。

【问题讨论】:

    标签: ruby-on-rails elasticsearch tire


    【解决方案1】:

    只需在模型中使用index_name "my-custom-name" 方法即可;示例见https://github.com/karmi/tire/blob/master/test/models/active_model_article_with_custom_index_name.rb

    当它已经存在时,Tire 不会尝试创建索引,因此当您创建索引、加载数据、启动应用程序时,一切都应该就位。

    另外,您可能希望使用 Elasticsearch 对索引别名的支持来更方便和透明地管理。请参阅轮胎的 API:https://github.com/karmi/tire/blob/master/test/integration/index_aliases_test.rb 和文档:http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/

    【讨论】:

    • 嗯,这似乎不太奏效-因为我需要轮胎“创建”到版本化名称,但从别名中“读取”(这样当我更改别名时'仍然可以工作)。在加载我的模块之前,我正在使用一个调用 "Tire::Model::Search.index_prefix "v#{version}"" 的脚本,这似乎过于复杂但正在工作
    【解决方案2】:

    补充@karmi 的答案。使用 index_name '我的自定义名称'。 由于这个原因,我遇到了错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-14
      • 2013-04-10
      • 2012-03-24
      • 2012-03-22
      • 1970-01-01
      • 2012-04-14
      • 2013-01-12
      • 1970-01-01
      相关资源
      最近更新 更多