Elasticsearch::Transport::Transport::Errors::BadRequest error heroku - ruby-on-rails

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.x.x, 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.

Related

ShopifySessionRepository.shop_storage is not configured

I created a very basic Shopify App, and when I install it through the https://XXX.ngrok.io/login page I see the confirmation screen, however when clicking install, Rails throws the ShopifySessionRepository.shop_storage is not configured error. If I ignore the warning and navigate into the store, I see that the App was installed successfully regardless.
My controller:
class SpaV1Controller < ApplicationController
include ShopifyApp::EmbeddedApp # cookie-less architecture
include ShopifyApp::RequireKnownShop # cookie-less architecture
def index
#shop_origin = current_shopify_domain
#products = ShopifyAPI::Product.find(:all, params: { limit: 10 })
end
end
I am trying to use the new cookieless App Bridge, and I suppose this can be connected?
I was having this issue.
I had this in my shopify_app.rb initializer:
config.shop_session_repository = 'Shop'
Then I needed to run the following:
$ rails generate shopify_app:shop_model
$ rails db:migrate RAILS_ENV=development

solidus_searchkick - undefined method `deep_symbolize_keys'

I am using Solidus and I want to implement a better search wiht elasticsearch, I'm using solidus_searchkick to do that. But I get the following error:
undefined method 'deep_symbolize_keys' for #<ActionController::Parameters:0x0000556eae99cda8>
At Spree::HomeController#index, that has:
Spree::HomeController.class_eval do
def index
#searcher = build_searcher(params.merge(include_images: true))
#products = #searcher.retrieve_products
#taxonomies = Spree::Taxonomy.includes(root: :children)
end
end
I have NOT changed anything at Solidus' search options.
I get this error right after I run 'bundle install', installs everything just fine.
Then, I run 'rails s' and I get this error when I try to get my home or any other page that shows me any product.
Versions:
Rails: 5.1.6
Ruby: 2.5.1
solidus_searchkick: 0.3.4
Solidus: 2.5.0
This is an issue with the deprecated method deep_symbolize_keys in Rails 5.1. I just submitted a Pull Request for the solidus_searchkick gem. You can find it here https://github.com/elevatorup/solidus_searchkick/pull/6/files
If you point your solidus_searchkick gem to that branch it will work.

Whois gem not working in rails

class DomaincheckerController < ApplicationController
def index
end
def store
r =Whois.whois(secure_params['domain'])
render :text => "#{r}"
end
private
def secure_params
params.require(:whois).permit(:domain)
end
end
This is my domainchecker controller. The index method renders a form. After submitting the form it goes to store method. Here I am trying to use the whois gem. I have installed whois gem by running gem install whois. But I am getting this error.
uninitialized constant DomaincheckerController::Whois
The problem is that you installed the gem directly and not using bundler, therefore the Rails app can't find the dependency.
In order to install a gem in a Rails project you need to edit the Gemfile file and add the gem there. Once added, run
$ bundle
in order to install the dependency. Check the documentation about the Gemfile.

heroku undefined method empty? when upgrading my app to ruby 2.0

I've recently upgraded my Heroku app from Cedar-10 to Cedar-14 with no problems (still using ruby 1.9.3). Then I tried upgrading my app to use ruby 2.0.0-p645 and push it to the heroku server. When I do this I can no longer access my app and I get the following error in the logs;
2015-07-09T12:27:37.480991+00:00 app[web.1]:
2015-07-09T12:27:37.480996+00:00 app[web.1]: NoMethodError (undefined method `empty?' for nil:NilClass):
2015-07-09T12:27:37.480998+00:00 app[web.1]: app/controllers/wines_controller.rb:18:in `index'
2015-07-09T12:27:37.480999+00:00 app[web.1]:
2015-07-09T12:27:37.481001+00:00 app[web.1]:
2015-07-09T12:27:37.481462+00:00 app[web.1]: Processing by WinesController#index as HTML
2015-07-09T12:27:37.481465+00:00 app[web.1]: Completed 500 Internal Server Error in 100.1ms
If I look at line 18 of the wines_controller I have the following;
respond_to do |format|
format.html
format.json {render json: #wines.as_json}
end
I thought it was something in my index.html, so I took that back to the this;
%h1 Wines
With just this one line in my index.html.haml it still had a problem.
If I try and access wines.json this works and gives me a list of my wines. Running on my development box using 2.0.0 works fine and all my tests pass.
Update: Add controller & more info on index.html
Here is my wines controller
def index
# Search via Ransack
#q = current_user.wines.includes(:wine_rack).unconsumed.order("LOWER(winery)").search(params[:q])
#wines = #q.result.page params[:page]
#total = #q.result.sum(:qty)
respond_to do |format|
format.html
format.json {render json: #wines.as_json}
end
end
In regards to my index.html.haml file I uploaded a version of my project which only included this one line;
%h1 Wines
There are no loops happening in the view and I still get the error.
Line 18 refers to the following line in my controller;
respond_to do |format|
I found the answer. I had to upgrade my newrelic_rpm. It's the only thing I've changed and now it works.
- newrelic_rpm (3.5.0)
+ newrelic_rpm (3.12.1.298)
I tested by loading up another instance of heroku and sending my app there a few times with various bits of the controller & view cut out, nothing changed until I remarked out newrelic_rpm gem and it started working. So I upgraded it instead of removing the gem and now it works.
The only reason I removed it was due to me looking for differences between development and production. It was marked as a production only gem in my Gemfile.

foursquare api calls failing in heroku console with quimby gem

I am using the quimby gem to interface with foursquare's venue api. I have an establishment model, I am trying to run a method that looks up an establishment on foursquare so that I can then do stuff with the data 4sq provides.
in my establishment model I've created this method
def find_on_foursquare
Foursquare.verbose = true
foursquare = Foursquare::Base.new(FOURSQUARE_ID, FOURSQUARE_SECRET)
begin
venue = foursquare.venues.search(:ll => "#{self.lat},#{self.long}",
:query => self.name,
:categoryId => '4d4b7105d754a06374d81259')['nearby'][0]
puts venue
rescue
puts 'FAILED!'
end
end
when I execute this from localhost console everything runs smoothly. However, when I push to heroku and try to execute from heroku console it fails with "! Internal server error"
Any ideas what I am doing wrong and/or how to debug this?
Some curious lines from the heroku logs:
2011-12-29T17:09:29+00:00 app[web.1]: [foursquare] GET https://api.foursquare.com/v2/venues/search
2011-12-29T17:09:29+00:00 app[web.1]: [foursquare] PARAMS: {"ll"=>"42.344432,-71.098326", "query"=>"Citizen", "categoryId"=>"4d4b7105d754a06374d81259"}
2011-12-29T17:09:29+00:00 app[web.1]: /app/.bundle/gems/ruby/1.9.1/gems/typhoeus-0.3.3/lib/typhoeus/easy.rb:397: [BUG] Segmentation fault
2011-12-29T17:09:29+00:00 app[web.1]: ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
Solution: I had to downgrade Typhoeus to 0.2.4 to get the Quimby gem to talk to Foursquare when deployed on Heroku. Working perfectly now.

Resources