[英]How to remove _source from search results in Tire gem for elasticsearch
I'm indexing attachments in Elasticsearch (via Tire gem) and they're quite large. 我正在索引Elasticsearch中的附件(通过Tire gem)并且它们非常大。 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. 这似乎是因为Tire (ES)在其搜索结果中包含了文档的整个
_source
。 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: 直接与ES通信可以包括
partial_fields
元素来限制它:
"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
...
There is no direct support for partial_fields
in Tire yet. 目前还没有对Tire中
partial_fields
直接支持。
Limit the response by using the fields
option for the search method: 使用搜索方法的
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.