1

Having a tough time wrapping my head around Tire's syntax, that of Elasticsearch and how they map together.

I have successfully indexed PDFs in a Rails app via Tire. But I need to break the full reports down into individual pages so queries can be more granular. It's easy enough to split the PDFs into individual pages and add them to a Page model that belongs_to the full Report model. What I'm struggling with is how to set up the mapping and where?!? I'd like to take advantage of Elasticsearch's Parent Field mapping so I can realize this ultimate goal.

Hoping someone can set me straight.

Report model (this is working for me if I index an entire PDF as the :attachment):

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

  has_many :pages, :dependent => :destroy
  attr_accessible :filename, :title

  tire.mapping do
    indexes :id, :type =>'integer'
    indexes :title
    indexes :attachment, :type => 'attachment',
                            :fields => {
                            :content_type => { :store => 'yes' },
                            :author     => { :store => 'yes' },
                            :title      => { :store => 'yes' },
                            :attachment => { :term_vector => 'with_positions_offsets', :store => 'yes' },
                            :date       => { :store => 'yes' }
                          }
  end

  ...
end

Page model:

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

  belongs_to :report
  attr_accessible :filename, :page_num,

  tire.mapping do
    indexes :id, :type => 'integer'
    indexes :page_num, :type => 'integer'
    indexes :report_id, :type => 'integer' ###<== how is this associated with _parent?
    indexes :attachment, :type => 'attachment',
                            :fields => {
                            ...
    ...
  end
end
Community
  • 1
  • 1
Meltemi
  • 37,979
  • 50
  • 195
  • 293

0 Answers0