I'm indexing attachments in Elasticsearch (via Tire gem) and they're quite large. For whatever reason, and I wasn't expecting this, the search is dog slow. It appears to be because Tire (ES) is including the entire _source
of the document in its search results. This is unnecessary but I can't figure out how to turn it off.
Communicating directly with ES one could include a partial_fields
element to restrict it:
"partial_fields" : {
"no_PDFs" : {
"exclude" : ["attachment", "reports.attachment"]
}
}
Anyone know how to exclude elements from Tire search?
class Report < ActiveRecord::Base
include Tire::Model::Search
include Tire::Model::Callbacks
...
tire.mapping do
indexes :id, :type =>'integer'
indexes :title
indexes :attachment, :type => 'attachment',
:fields => {
:author => { :store => 'yes' },
:attachment => { :term_vector => 'with_positions_offsets', :store => 'yes' },
:date => { :store => 'yes' }
}
end
def self.search(params)
tire.search do
query { string params[:query] } if params[:query].present?
highlight :attachment
end
end
...