ruby-on-rails - ElasticSearch和 cucumber

标签 ruby-on-rails elasticsearch cucumber capybara

当我尝试使用ElasticSearch访问页面时,我不确定为什么我的Cucumber测试失败了。我假设它与 capybara 如何运行页面有关。如果有帮助,我正在使用Poltergeist。

这是完整的痕迹:

400 : {"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[qMOd6ozIREy-7dO8R5Kp6Q][businesses_test][4]: SearchParseException[[businesses_test][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"dis_max\":{\"queries\":[{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"boost\":10,\"analyzer\":\"searchkick_search\"}},{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"boost\":10,\"analyzer\":\"searchkick_search2\"}},{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"fuzziness\":1,\"max_expansions\":3,\"analyzer\":\"searchkick_search\"}},{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"fuzziness\":1,\"max_expansions\":3,\"analyzer\":\"searchkick_search2\"}}]}},\"size\":100000,\"from\":0,\"fields\":[]}]]]; nested: QueryParsingException[[businesses_test] [match] analyzer [searchkick_search] not found]; }{[qMOd6ozIREy-7dO8R5Kp6Q][businesses_test][3]: SearchParseException[[businesses_test][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"dis_max\":{\"queries\":[{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"boost\":10,\"analyzer\":\"searchkick_search\"}},{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"boost\":10,\"analyzer\":\"searchkick_search2\"}},{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"fuzziness\":1,\"max_expansions\":3,\"analyzer\":\"searchkick_search\"}},{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"fuzziness\":1,\"max_expansions\":3,\"analyzer\":\"searchkick_search2\"}}]}},\"size\":100000,\"from\":0,\"fields\":[]}]]]; nested: QueryParsingException[[businesses_test] [match] analyzer [searchkick_search] not found]; }{[qMOd6ozIREy-7dO8R5Kp6Q][businesses_test][1]: SearchParseException[[businesses_test][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"dis_max\":{\"queries\":[{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"boost\":10,\"analyzer\":\"searchkick_search\"}},{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"boost\":10,\"analyzer\":\"searchkick_search2\"}},{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"fuzziness\":1,\"max_expansions\":3,\"analyzer\":\"searchkick_search\"}},{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"fuzziness\":1,\"max_expansions\":3,\"analyzer\":\"searchkick_search2\"}}]}},\"size\":100000,\"from\":0,\"fields\":[]}]]]; nested: QueryParsingException[[businesses_test] [match] analyzer [searchkick_search] not found]; }{[qMOd6ozIREy-7dO8R5Kp6Q][businesses_test][2]: SearchParseException[[businesses_test][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"dis_max\":{\"queries\":[{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"boost\":10,\"analyzer\":\"searchkick_search\"}},{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"boost\":10,\"analyzer\":\"searchkick_search2\"}},{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"fuzziness\":1,\"max_expansions\":3,\"analyzer\":\"searchkick_search\"}},{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"fuzziness\":1,\"max_expansions\":3,\"analyzer\":\"searchkick_search2\"}}]}},\"size\":100000,\"from\":0,\"fields\":[]}]]]; nested: QueryParsingException[[businesses_test] [match] analyzer [searchkick_search] not found]; }{[qMOd6ozIREy-7dO8R5Kp6Q][businesses_test][0]: SearchParseException[[businesses_test][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"dis_max\":{\"queries\":[{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"boost\":10,\"analyzer\":\"searchkick_search\"}},{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"boost\":10,\"analyzer\":\"searchkick_search2\"}},{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"fuzziness\":1,\"max_expansions\":3,\"analyzer\":\"searchkick_search\"}},{\"multi_match\":{\"fields\":[\"_all\"],\"query\":\"\",\"use_dis_max\":false,\"operator\":\"and\",\"fuzziness\":1,\"max_expansions\":3,\"analyzer\":\"searchkick_search2\"}}]}},\"size\":100000,\"from\":0,\"fields\":[]}]]]; nested: QueryParsingException[[businesses_test] [match] analyzer [searchkick_search] not found]; }]","status":400} (Tire::Search::SearchRequestFailed)
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/tire-0.6.2/lib/tire/search.rb:145:in `perform'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/tire-contrib-0.1.3/lib/tire/rails/logger/instrumentation.rb:14:in `block in perform_with_instrumentation'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.2/lib/active_support/notifications.rb:159:in `block in instrument'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.2/lib/active_support/notifications.rb:159:in `instrument'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/tire-contrib-0.1.3/lib/tire/rails/logger/instrumentation.rb:13:in `perform_with_instrumentation'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/tire-0.6.2/lib/tire/search.rb:43:in `json'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/searchkick-0.5.0/lib/searchkick/search.rb:351:in `search'
      /Users/backend2_tlp/repositories/viasam/app/controllers/providers_controller.rb:74:in `set_locations'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/abstract_controller/base.rb:189:in `process_action'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_controller/metal/rendering.rb:10:in `process_action'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:473:in `_run__4334027495525200954__process_action__callbacks'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:80:in `run_callbacks'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/abstract_controller/callbacks.rb:17:in `process_action'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_controller/metal/rescue.rb:29:in `process_action'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.2/lib/active_support/notifications.rb:159:in `block in instrument'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.2/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.2/lib/active_support/notifications.rb:159:in `instrument'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.2/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/abstract_controller/base.rb:136:in `process'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/abstract_controller/rendering.rb:44:in `process'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_controller/metal.rb:195:in `dispatch'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_controller/metal.rb:231:in `block in action'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:80:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:48:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_dispatch/journey/router.rb:71:in `block in call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_dispatch/journey/router.rb:59:in `each'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_dispatch/journey/router.rb:59:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:680:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/omniauth-1.2.1/lib/omniauth/strategy.rb:186:in `call!'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/omniauth-1.2.1/lib/omniauth/strategy.rb:164:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/omniauth-1.2.1/lib/omniauth/builder.rb:59:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/route_downcaser-0.2.1/lib/route_downcaser/downcase_route_middleware.rb:21:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/conditionalget.rb:25:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_dispatch/middleware/flash.rb:241:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_dispatch/middleware/cookies.rb:486:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.2/lib/active_record/query_cache.rb:36:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:373:in `_run__77402820920205634__call__callbacks'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:80:in `run_callbacks'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/cucumber-rails-1.4.0/lib/cucumber/rails/action_controller.rb:10:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.2/lib/rails/rack/logger.rb:38:in `call_app'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.2/lib/rails/rack/logger.rb:20:in `block in call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.2/lib/active_support/tagged_logging.rb:67:in `block in tagged'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.2/lib/active_support/tagged_logging.rb:25:in `tagged'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.2/lib/active_support/tagged_logging.rb:67:in `tagged'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.2/lib/rails/rack/logger.rb:20:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_dispatch/middleware/request_id.rb:21:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/activesupport-4.0.2/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/actionpack-4.0.2/lib/action_dispatch/middleware/static.rb:64:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.2/lib/rails/engine.rb:511:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/railties-4.0.2/lib/rails/application.rb:97:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/builder.rb:138:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/urlmap.rb:65:in `block in call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/urlmap.rb:50:in `each'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/urlmap.rb:50:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/capybara-2.1.0/lib/capybara/server.rb:19:in `call'
      /Users/backend2_tlp/.rvm/gems/ruby-2.0.0-p451/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
      /Users/backend2_tlp/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
      /Users/backend2_tlp/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
      /Users/backend2_tlp/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'

cucumber 功能
@javascript
Scenario: follow link in welcome email while logged out
  When I create a new account
  And I am logged out
  And I follow the link in the provider welcome email
  Then I should be asked to login
  And I should be on the lugares de trabajo page

cucumber 步骤
When /^I create a new account$/ do
  subcategory = Subcategory.first.name
  fill_in('provider[url]', with: @provider.url)
  fill_in('provider[email]', with: "test@example.com")
  fill_in('provider[first_name]', with: @provider.first_name)
  fill_in('provider[last_name]', with: @provider.last_name)
  select(subcategory, from: 'provider[subcategory_id]')
  select(@provider.title, from: 'provider[title]')
  fill_in('provider[password]', with: "password")
  fill_in('provider[password_confirmation]', with: "password")
  click_on("submit")
end

And /^I am logged out$/ do
  page.driver.remove_cookie("_viasam_session")
end

And /^I follow the link in the provider welcome email$/ do
  email = ActionMailer::Base.deliveries.last.body
  reset_link = email.match(/(\/proveedores.*?trabajo)/).captures.first.to_s.strip
  visit(reset_link)
end

Then /^I should be asked to login$/ do
  current_path_is("/proveedor/ingresa")
end

And /^I should be on the lugares de trabajo page$/ do
  fill_in("provider_email", with: "test@example.com")
  fill_in("provider_password", with: "password")
  click_on("provider_login_button")
  current_path_is(set_locations_provider_es_path(@provider))
end

设置位置 Action
def set_locations
  @provider_locations = @provider.locations
  @businesses = Business.search(params[:query], page: params[:page])
end

business.rb
class Business < ActiveRecord::Base

  searchkick autocomplete: ['commercial_name']
  searchkick settings: {number_of_shards: 1}

  validates_presence_of :commercial_name

  has_many :locations, :dependent => :destroy

  accepts_nested_attributes_for :locations,
    reject_if: lambda { |a| a[:street_address].blank? },
    :allow_destroy => true
end

最佳答案

我几天前就知道了。我需要更改 Controller Action 。

def set_locations
  @provider_locations = @provider.locations
  if params[:query].present?
    @businesses = Business.search(params[:query], page: params[:page])
  else
    @businesses = []
  end
end

关于ruby-on-rails - ElasticSearch和 cucumber ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22693712/

相关文章:

javascript - 使用带有动态生成的输入的 form_tag 提交数组

ruby-on-rails - 在 Ruby on Rails 开发中使用 Cucumber 传递 autospec 中的选项

Java 在测试期间重复

cucumber - cucumber / capybara -如何使用XPath搜索特定按钮?

javascript - 全日历 Rails7

ruby-on-rails - 测量 SAAS 应用程序带宽使用情况

ruby-on-rails - 如何在 heroku Elastic Cloud、Elastic Search 5.x 上进行身份验证?

elasticsearch - Serilog和Elasticsearch 5.0

ruby-on-rails - 在 rails 4 中重构一个大的 routes.rb 文件

java - 在logstash中使用jdbc输入插件时的时间变化