Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8049453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:47:23+00:00 2026-06-05T06:47:23+00:00

I have some ruby class class MyClass include Tire::Model::Persistence attr_accessor :date mapping do index_name

  • 0

I have some ruby class

class MyClass
   include Tire::Model::Persistence
   attr_accessor :date

   mapping do
      index_name Proc.new{|o| "my_class_#{o.date_index}" }  # How to?
   end

   def initialize(d)
     @date = d
   end

   def date_index
      @date.strftime("%m%y")
   end
end

How can I set the index_name dynamically, after initializing class?

Ruby (1.9.3)
Rails(3.2.3)
Tire (0.4.2)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:47:24+00:00Added an answer on June 5, 2026 at 6:47 am

    This is still an unresolved problem with a number of edge-cases. There are many ways how to look at indices in elasticsearch.

    First, it’s perfectly possible to define a dynamic index name like this:

    Article.index_name { "articles-#{Time.now.year}" }
    

    See https://github.com/karmi/tire/blob/master/lib/tire/model/naming.rb#L10-35

    Second, a much more flexible, powerful and future-proof approach is to use aliases feature in elasticsearch.

    See https://github.com/karmi/tire/blob/master/test/integration/index_aliases_test.rb#L66 for inspiration on what’s possible.

    Then, you create something like mydocs_current index alias (a “virtual index”), and point it to a specific physical index, let’s say mydocs_2012_06. You then rotate this index in cron jobs, etc.

    When searching, you can either use the Tire.search DSL or inject a different index/alias name into the model class on thy fly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have some code in Ruby here below: class A @@lock = Monitor.new class
I'm new in the world of Ruby on Rails. I have some problems to
Complete new person to Ruby and Rails here... Have tried some tutorials in the
I'm messing around in Ruby some more. I have a file containing a class
Given a model: class Person validates_lenght_of :name, :maximum => 50 end I have some
If I have a custom Ruby class representing some string type, as in class
I have some existing ruby classes in a app/classes folder: class A ... end
I have some command-line ruby scripts for things like pre-processing text files before uploading
I have some difficulties for using Ruby block, passing in a method. As in
I have read some where that ruby fork are COW friendly ok here the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.