Elasticsearch :: Transport :: Transport :: Errors :: BadRequest error heroku

时间:2017-07-16 05:05:50

标签: ruby-on-rails elasticsearch heroku

我有一个rails应用程序,其搜索系统依赖于elasticsearch,我已经使用盆景插件将其推送到heroku上,但每当我尝试在我的应用程序上搜索某些内容时,它会在日志中给我这个错误。

2017-07-16T04:04:44.083489+00:00 app[web.1]: Completed 500 Internal Server Error in 18ms (ActiveRecord: 1.9ms)
2017-07-16T04:04:44.084229+00:00 app[web.1]:   app/controllers/search_controller.rb:7:in `show'
2017-07-16T04:04:44.084222+00:00 app[web.1]: Elasticsearch::Transport::Transport::Errors::BadRequest ([400] {"error":{"root_cause":[{"type":"parsing_exception","reason":"no [query] registered for [filtered]","line":1,"col":22}],"type":"parsing_exception","reason":"no [query] registered for [filtered]","line":1,"col":22},"status":400}):

我的Elasticsearch控制器

class SearchController < ApplicationController
  before_action :beautify_url
  layout "simple"

  def show
    @post_records = Post.search(query_term).paginate(page: params[:page]).records
    @posts = @post_records.to_a.select { |post| post.published? }
    @users = User.search(query_term).records.to_a
    @tags = Tag.search(query_term).records
  end

  def users
    @users = User.search(query_term).records.to_a
  end

  private

    def beautify_url
      if params[:search].present?
        case params[:action]
        when "show"
          redirect_to search_url(q: params[:search][:q])
        when "users"
          redirect_to search_users_url(q: params[:search][:q])
        end
      end
    end

    def query_term
      params[:q] || ''
    end
end

请帮助!!

1 个答案:

答案 0 :(得分:1)

盆景支持。目前正在Elasticsearch 5.x上配置盆景群集,自Elasticsearch 5.0起,filtered查询已被删除。尝试在5.x中使用filtered查询会导致您看到的错误消息。

根据您的共享,我想最有可能的问题是客户端使用的是已弃用的Query DSL版本。这表明宝石版本不兼容。

您可以通过命令行运行以下内容来检查Elasticsearch宝石的版本:

bundle show | grep elasticsearch

如果它们不是5.x.x,请在Gemfile中更新它们:

gem "elasticsearch", "~> 5"
gem "elasticsearch-rails", "~> 5"

并运行bundle update elasticsearch elasticsearch-rails。将更改推送到Heroku并再次尝试搜索。

如果这没有用,请发送电子邮件至support@bonsai.io,我们会帮您解决。