- 拥有Rails 4应用程序,想要使用ElasticSearch添加全文搜索。
- 该应用程序运行正常在本地使用的工头,但提交的在Heroku上部署版本的搜索 查询时,我得到一个错误:(参见下面的完整的错误日志) “IndexMissingException”
- 我认为这个问题是有关我没有正确指向heroku上的ElasticSearch索引。我试过了,但说实话,我并不完全理解“使用索引部分”,我认为这是问题的根源。
任何建议,可以提供正确的设置与Heroku的ElasticSearch的Rails 4应用程序将不胜感激!Heroku上的Rails 4应用程序获得Elasticsearch IndexMissingException
这里有一些细节,希望可以帮助调试。
的Ruby/Rails版本
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin14.0]
Rails 4.2.1
从Heroku的日志
2015-04-12T20:52:36.506728+00:00 app[web.1]: Started GET "/posts?utf8=%E2%9C%93&q=better" for 98.14.231.17 at 2015-04-12 20:52:36 +0000
2015-04-12T20:52:36.553113+00:00 app[web.1]:
2015-04-12T20:52:36.553116+00:00 app[web.1]: ActionView::Template::Error ([404] {"error":"IndexMissingException[[posts] missing]","status":404}):
2015-04-12T20:52:36.553118+00:00 app[web.1]: 7: <% end %>
2015-04-12T20:52:36.553120+00:00 app[web.1]: 8:
2015-04-12T20:52:36.553131+00:00 app[web.1]:
2015-04-12T20:52:36.553121+00:00 app[web.1]: 9: <ul>
2015-04-12T20:52:36.553123+00:00 app[web.1]: 10: <% @posts.each do |post| %>
2015-04-12T20:52:36.550831+00:00 app[web.1]: Rendered posts/index.html.erb within layouts/application (27.2ms)
2015-04-12T20:52:36.553124+00:00 app[web.1]: 11: <li>
2015-04-12T20:52:36.553126+00:00 app[web.1]: 12: <%= post.content %>
2015-04-12T20:52:36.553129+00:00 app[web.1]: app/views/posts/index.html.erb:10:in `_app_views_posts_index_html_erb___4115668764297473519_69883416675900'
2015-04-12T20:52:36.553127+00:00 app[web.1]: 13: </li>
2015-04-12T20:52:36.553132+00:00 app[web.1]:
2015-04-12T20:52:36.549950+00:00 app[web.1]: Post Search (18.6ms) {index: "posts", type: "post", q: "better"}
2015-04-12T20:52:36.516050+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "q"=>"better"}
2015-04-12T20:52:36.515947+00:00 app[web.1]: Processing by PostsController#index as HTML
2015-04-12T20:52:36.551104+00:00 app[web.1]: Completed 500 Internal Server Error in 35ms (ActiveRecord: 0.0ms | Elasticsearch: 18.6ms)
的Gemfile
source 'https://rubygems.org'
ruby '2.1.3'
gem 'rails', '4.2.1'
gem 'pg'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
group :development, :test do
gem 'byebug'
gem 'web-console', '~> 2.0'
gem 'spring'
end
gem 'rails_12factor', group: :production
gem "figaro"
gem 'annotate', '~> 2.6.5', group: :development
gem 'pry-rails', group: :development
gem 'bootstrap-sass', '~> 3.3.4'
gem 'autoprefixer-rails'
gem 'font-awesome-sass'
gem 'ffaker'
gem 'react-rails', '~> 1.0.0.pre', github: 'reactjs/react-rails'
gem 'thin'
gem 'elasticsearch-model'
gem 'elasticsearch-rails'
gem 'bonsai-elasticsearch-rails'
型号
require 'elasticsearch/model'
class Post < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
end
Post.import
控制器
class PostsController < ApplicationController
def index
if params[:q].nil?
@posts = []
else
@posts = Post.search(params[:q])
end
end
end
查看
<%= form_for posts_path, method: 'get' do |f| %>
<%= f.label "Search for" %>
<%= text_field_tag :q, params[:q] %>
<%= submit_tag "Go", name: nil %>
<% end %>
<ul>
<% @posts.each do |post| %>
<li>
<%= post.content %>
</li>
<% end %>
</ul>
Heroku的盆景附加组件
我跟着instructions at Heroku for installing Bonsai
创建索引
curl -X POST http://[[MY BONSAI URL]]
,并得到:
{"ok":true,"acknowledged":true}
正如我所说,我认为这个问题是我不能正常使用绑定到该/指点到索引。任何意见,将不胜感激!