0

我在 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
  ...
4

1 回答 1

2

目前还没有对partial_fieldsTyre 的直接支持。

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
于 2012-09-23T07:34:14.383 回答