0

I am using elasticsearch-rails gem in my rails app. 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. Here is the index_name method define in gem

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

2 Answers 2

1

This feature has been inplemented here and released to rubygems.

Sign up to request clarification or add additional context in comments.

Comments

0

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

3 Comments

I want to pass the index name as a block that's why i used curly braces.
May I ask what is the gain of passing a block instead of a dynamic value? wont the block be executed as the dynamic value?
I am trying to create a dynamic index for each account which is logged in. I did this when i was using Tire gem and this functionality was supported in Tire but not in this gem as i mentioned in the question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.