【发布时间】:2012-09-22 00:33:06
【问题描述】:
我正在 Elasticsearch 中索引附件(通过 Tire gem),它们非常大。无论出于何种原因,我没想到会这样,搜索速度很慢。这似乎是因为 Tire (ES) 在其搜索结果中包含了文档的整个 _source。这是不必要的,但我不知道如何关闭它。
直接与 ES 通信可以包含一个 partial_fields 元素来限制它:
"partial_fields" : {
"no_PDFs" : {
"exclude" : ["attachment", "reports.attachment"]
}
}
有人知道如何从轮胎搜索中排除元素吗?
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
...
【问题讨论】:
标签: ruby-on-rails elasticsearch tire