我正在使用Elasticsearch & Typeahead在我的Rails應用程序中執行自動完成。我的想法從這裏Typeahead/Rails:無法正常工作
我elasticsearch自動完成配置正確,因爲它,當我直接通過瀏覽器訪問它的工作原理。但是,當我嘗試使用typeahead從自動完成查詢調用顯示數據時,它甚至不會在我的調試器中觸發。這裏是我的形式&的JavaScript,其中預輸入被稱爲
表
<script>
$('#autcomplete_search').typeahead({
highlight: true
},
{
name: 'apple_game',
remote: "/search/autocomplete?query=%QUERY"
});
</script>
<h1>Keyword</h1>
<form action="/search/keyword">
<div>
<%= text_field_tag :query, params[:query], class: "form-control", id: "autcomplete_search" %>
<br/>
<br/>
</div>
<div>
<input type="submit">/</input>
</div>
</form>
控制器
def autocomplete
es = ESClient.get_client
games = es.suggest index: 'games',
body: {
apple_game: {
text: params[:keyword],
completion: {
field: "title"}
}
}
render json: games
end
樣的瀏覽器從結果控制器方法
{
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"apple_game": [
{
"text": "ma",
"offset": 0,
"length": 2,
"options": [
{
"text": "Macabre Mysteries: Curse of the Nightingale Collector's Edition HD",
"score": 1
},
{
"text": "Mad Cop - Police Car Race and Drift (Ads Free)",
"score": 1
},
{
"text": "Mad Freebording (Snowboarding)",
"score": 1
},
{
"text": "Mad Merx: Nemesis",
"score": 1
},
{
"text": "Mad River Whitewater Kayak Rush",
"score": 1
}
]
}
]
}
編輯 每當預輸入運行
Uncaught Error: missing source
什麼版本的預輸入您使用的是 –
我使用v0.10.1從http://twitter.github.io/typeahead。 js/ – user2158382
,請張貼您想要打印的字段的映射 –