How do you set _parent using Tire in a Rails model?


(Meltemi) #1

Apologies for my dense-ity. Elasticsearch & Tire have my head spinning...

I'm looking for an example of how to index a parenthttp://www.elasticsearch.org/guide/reference/mapping/parent-field.htmlchild relationship between a
Page and a Report model in Rails.

Should I use the report_id attribute of Page and index it as "_parent" or
do something like Karmi suggests herehttp://stackoverflow.com/questions/11692560/elasticsearch-tire-and-nested-queries-associations-with-activerecord.
And if so will the _parent relationship be established automatically?

In my Page model I have:

class Page < ActiveRecord::Base
include Tire::Model::Search
include Tire::Model::Callbacks

belongs_to :report
attr_accessible :filename, :page_num, :parent_code

tire.mapping do
indexes :id, :type => 'integer'
indexes :report_id, :type => 'integer' # but how is this
associated with _parent?
indexes :parent_code
...
end
end

--


(system) #2