gpt4 book ai didi

ruby-on-rails - 如何从Tire gem的搜索结果中删除_source以进行Elasticsearch

转载 作者:行者123 更新时间:2023-12-03 01:09:18 25 4
gpt4 key购买 nike

我正在Elasticsearch中索引附件(通过 Tire gem),它们很大。无论出于什么原因,我都没想到这一点,搜索速度很慢。似乎是因为 Tire (ES)在其搜索结果中包括了文档的整个_source。这是不必要的,但我不知道如何将其关闭。

直接与ES通信可以包含一个partial_fields元素来限制它:

"partial_fields" : {
"no_PDFs" : {
"exclude" : ["attachment", "reports.attachment"]
}
}

有人知道如何从Tire搜索中排除元素吗?
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

关于ruby-on-rails - 如何从Tire gem的搜索结果中删除_source以进行Elasticsearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12539721/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com