简体   繁体   English

elasticsearch-rails gem中的动态index_name

[英]Dynamic index_name in elasticsearch-rails gem

I am using elasticsearch-rails gem in my rails app. 我在Rails应用程序中使用elasticsearch-rails gem。 I want to set index name dynamically. 我想动态设置索引名称。 In model i did this: 在模型中,我这样做:

index_name {Account.current_account.subdomain}

Currently there is no support in the gem to do this. 目前,gem中尚不支持此操作。 Here is the index_name method define in gem 这是在gem中定义的index_name方法

naming.rb naming.rb

# TODO: Dynamic names a la Tire -- `Article.index_name { "articles-#{Time.now.year}" }`
#
def index_name name=nil
    @index_name = name || @index_name || self.model_name.collection.gsub(/\//, '-')
end

How can i get this working? 我该如何工作? Thanks 谢谢

此功能已在此处得到补充,并已发布到rubygems。

So you tried something like this and it didn't work? 因此,您尝试了类似的操作,但没有成功? as it works for me? 对我有用吗?

class Account < ActiveRecord::Base
  include Elasticsearch::Model

  index_name(Account.current_account.subdomain) # without the curly braces

  mapping do
     ...
  end
end

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

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