簡體   English   中英

如何從Tire gem中的搜索結果中刪除_source for elasticsearch

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM