[英]How to remove _source from search results in Tire gem for elasticsearch
我正在索引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
...
目前还没有对Tire中partial_fields
直接支持。
使用搜索方法的fields
选项限制响应:
require 'tire'
Tire.index 'bigfields-test' do
delete and create
store title: 'Test 1', content: 'x'*100_000
store title: 'Test 2', content: 'x'*100_000
refresh
end
s = Tire.search 'bigfields-test', fields: 'title' do
query { string 'test' }
end
p s.results
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.