简体   繁体   中英

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

I have a rails app which has search system which depends on elasticsearch, i have pushed it on heroku using the bonsai addon, but whenever i try to search something on my app it give me this error in the log.

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}):

My Elasticsearch Controller

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

Please help!!

Bonsai support here. Bonsai clusters are currently being provisioned on Elasticsearch 5.x, and as of Elasticsearch 5.0, the filtered query has been removed. Attempting to use a filtered query in 5.x results in that error message you're seeing.

From what you've shared, I would say the most likely issue is that the client is using a deprecated version of the Query DSL. That would suggest an incompatible gem version.

You can check what version your Elasticsearch gems are by running this from a command line:

bundle show | grep elasticsearch

If they are not 5.xx, update them in your Gemfile:

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

And run bundle update elasticsearch elasticsearch-rails . Push the change to Heroku and try your search again.

If that doesn't help, shoot an email to support@bonsai.io and we'll help you sort it out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM