我在 Elasticsearch 中索引附件(通过Tire gem),它们非常大。无论出于何种原因,我没想到会这样,搜索速度很慢。这似乎是因为轮胎(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
...