简体   繁体   中英

Tire create index using custom name without tire:import

Looking at this answer, Update ElasticSearch mapping in production (Tire) , the main way to import into a new index name is using rake

I'm using a mysqlriver to import my data (there's a lot of it, and I like the control). When I first load my ruby model with the tire settings, it automatically creates an index. How do I change the index name that it uses?

  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

My goal is to have it create an index named "tag_version_1" so I can create an alias and have 0-downtime index changes.

Just use the index_name "my-custom-name" method in your model; see https://github.com/karmi/tire/blob/master/test/models/active_model_article_with_custom_index_name.rb for an example.

Tire won't attempt to create the index when it already exists, so when you create the index, load your data, start the app, everything should snap into place.

Also, you might want to use the Elasticsearch's support for index aliases for more convenient and transparent management of. See Tire's API: https://github.com/karmi/tire/blob/master/test/integration/index_aliases_test.rb and the documentation: http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases/

Adding on to @karmi's answer. Use index_name 'my-custom-name'. I was facing errors because of this reason.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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