2012-08-10 56 views
0

我必須在這裏失去一些東西,但是當我嘗試使用Elasticsearch搜索時突出顯示,我根本沒有看到任何突出顯示,但也沒有錯誤。我不認爲這是一個輪胎問題,但我提到輪胎以防萬一它很重要。索引使用輪胎是非常簡單(取出來簡潔某些字段):Elasticsearch與輪胎,突出顯示不工作

mapping :_source => { :excludes => ['attachment'] } do 
    indexes :id, :type => 'integer' 
    indexes :title, :store => true 
    indexes :attachment, :type => 'attachment', :_source => { :enabled => false } 
end 

使用curl,我可以試試這個查詢,它工作正常,但有一個在結果沒有高亮:

curl -XPOST http://localhost:9200/myobject/_search\?pretty\=true -d '{    
    "query": {"query_string": {"query": "foobar"}}, 
    "highlight": {"fields": {"Title":{}}} 
}' 

請注意,我在映射中添加了「:store => true」來確保,但我認爲應該不需要突出顯示工作。所以我猜我在映射或查詢規範中缺少某些東西,但我沒有看到它。任何建議將非常感激。謝謝。

回答

2

字段名稱在elasticsearch中區分大小寫。 Titletitle是兩個不同的領域。試試這個查詢:

curl -XPOST http://localhost:9200/myobject/_search\?pretty\=true -d '{    
    "query": {"query_string": {"query": "foobar"}}, 
    "highlight": {"fields": {"title":{}}} 
} 
+1

輝煌,謝謝。被索引的原始數據對象中的字段被稱爲「標題」,但看起來輪胎映射是「:title」將其映射爲小寫,我應該在curl的輸出中注意到,但錯過了某種方式。捲曲現在起作用,但使用Tire並不總是能夠突出顯示權利。單行「s = MyObject.search(q,:highlight =>:title)」不起作用,但使用「highlight:title」進行塊搜索。無論如何,非常感謝您的快速幫助。 – Masonoise 2012-08-10 20:21:51