2015-08-28 33 views
2

我試圖從Elasticsearch-rails gem中獲取亮點,但是我無法使其工作。Elasticsearch-rails,亮點查詢

我的搜索方法:

​​

當我映射我在查看結果,以檢查是否有任何亮點,我得到的false數組:

= @results.map(&:highlight?) 

我通過Elasticsearch閱讀docs here:https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html和寶石的文檔在這裏:https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-model和我的查詢似乎是正確的。不知道如何繼續。

+0

'_all'在elasticsearch代表實際現場'_all'包含所有的字段組合。所以如果你有'name'和'descrption',所有的都會包含'name' +'description' ...這對調試很有用 – equivalent8

回答

2

顯然,解決方案是使用"*"而不是"_all"

query = { 
    query: { 
    filtered: { 
     query: { 
     match: { 
      _all: params[:q] 
     } 
     }, 
     filter: { 
     term: { 
      active: true 
     } 
     } 
    }, 
    }, 
    highlight: { 
    tags_schema: "styled", 
    fields: { 
     :"*" => {} 
    } 
    } 
}