1

I'm newbie to Elasticsearch and Tire. I have to classes: PersonRecord and Bookmark-PersonRecord contains attributes like name, birthday, location, etc, while Bookmark contains PersonRecord which is bookmarked and a user who bookmark it. PersonRecord class has_many Bookmarks.

Now I want to index on PersonRecord and Bookmark for elastic search, the goal is to boost the PersonRecord that has been bookmarked by the user to rank on top. To do that I need to index the user_id as well. The bookmark class looks like:

class Bookmark
  include Mongoid::Document

  belongs_to :person_record, index: true, foreign_key: :pr_id, touch: true
  belongs_to :user, index: true

end

I tried to find documents but didn't find a clear solution. So I'm planning to do something like this in the mapping:

  indexes :bookmarks,  type: 'object',
    properties: {
      user: {
          type: 'multi_field',
          fields: {
              id: {type: 'string',  index: 'not_analyzed'},
          }
      }
    }

Not sure is it the way to index on user_id? Or can I simplify it to something like

indexes :user_ids, as: bookmarks.map {|b| b.user.id }

And do I need to put it in *to_indexed_json* as well? Thanks!

4

0 回答 0