2012-09-22 48 views
0

我在Elasticsearch中索引附件(通過輪胎寶石),它們非常大。無論出於何種原因,我並不期待這一點,搜索是狗慢。這似乎是因爲Tyre(ES)在其搜索結果中包含文檔的整個_source。這是不必要的,但我不知道如何關閉它。如何從彈性搜索的輪胎寶石的搜索結果中刪除_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 
    ... 

回答

2

在輪胎中沒有直接支持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 
+0

的偉大工程!謝謝!但是,傳遞多個字段的語法是什麼(或者可以使用'except'選項來排除字段)?我試過'領域:['title','id']',其中一些嘗試失敗了。我知道ES想要一個陣列,但Tyre似乎不想傳遞它......我錯過了什麼? – Meltemi

+0

明白了:'fields:'title,id''。我想這個空間並沒有從與ES通信的URL中剝離出來。 – Meltemi

+0

只是'發現'':include_in_all => false'。這可以用在映射中以消除:從所有結果中附加?例如:'索引:附件,:type =>'attachment',:include_in_all => false,...'?!? – Meltemi

相關問題