ruby-on-rails - 手动重新安装(没有自制程序)时,RSPEC找不到 Elasticsearch

标签 ruby-on-rails ruby elasticsearch rspec facets

我已经研究了这个问题几周了。我正在使用的Rails应用程序使用Elasticsearch 1.5。我当时使用自制软件管理Elasticsearch,并将Elasticsearch升级到2.x。该应用程序无法在此最新版本的Elasticsearch中运行,并且搜索功能完全停止工作(由于不赞成使用facet)。虽然计划在接下来的几个月中迁移到聚合,但是我还有其他问题需要解决,所以我 brew 了卸载新版本的Elasticsearch的工作。我们的应用程序的版本无法通过自制软件获得,因此我在线上找到了它,并使用zip下载并安装了它。搜索功能可以再次与该应用一起使用,但是现在rspec找不到 flex 搜索,也将完全无法运行。它说Elasticsearch正在启动,但随后引发错误:

Starting 1 Elasticsearch nodes...sh: elasticsearch: command not found. 

&然后出现此错误:
/.rvm/gems/ruby-2.0.0-p643/gems/elasticsearch-extensions-0.0.18
    /lib/elasticsearch/extensions/test
    /cluster.rb:240:in `sleep': execution expired (Timeout::Error)

为了开始进行从方面到聚合的迁移,我必须使rspec正常工作。在此先感谢您的帮助。我已经为我的elasticsearch位置设置了bash别名。我的猜测是rspec找不到手动安装的版本,但是我不清楚在哪里处理。
spec_helper code:

def start_es_server
  Elasticsearch::Extensions::Test::Cluster.start(nodes: 1) unless   Elasticsearch::Extensions::Test::Cluster.running?

  # create index(s) to test against.
  create_es_index(Item)
end

def stop_es_server
  Elasticsearch::Extensions::Test::Cluster.stop if Elasticsearch::Extensions::Test::Cluster.running?
end

RSpec.configure do |config|
  config.include Capybara::DSL
  config.mock_with :rspec
  config.use_transactional_fixtures = true
  config.infer_spec_type_from_file_location!

  config.raise_errors_for_deprecations!  

  config.expect_with(:rspec) { |c| c.syntax = [:should, :expect] }
  config.mock_with :rspec do |mocks|
    mocks.syntax = [:should, :expect]
    mocks.verify_partial_doubles = true
  end

最佳答案

我通过查看https://github.com/elastic/elasticsearch-ruby/blob/b3cfdcbde678c2704c0a557a163782b9e027d144/elasticsearch-extensions/lib/elasticsearch/extensions/test/cluster.rb找到了这个问题的答案。可以传递给start方法的可选参数列表包括一个称为:command的参数,默认为'elasticsearch'。可以使用指向您的elasticsearch位置的直接路径来覆盖它:

elasticsearch = '/usr/local/elasticsearch-1.5.2/bin/elasticsearch'
Elasticsearch::Extensions::Test::Cluster.start(nodes: 1, command: elasticsearch) unless Elasticsearch::Extensions::Test::Cluster.running?

关于ruby-on-rails - 手动重新安装(没有自制程序)时,RSPEC找不到 Elasticsearch ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34688209/

相关文章:

java - 如何使用elasticsearch进行分页?来自 vs 滚动 API

ruby-on-rails - 干燥 rails View : partial vs helper

java - 如何让 Ruby 程序与 Java 程序一起工作?

arrays - All_else 方法 (Ruby)

elasticsearch - logstash不将日志推送到AWS Elasticsearch

php - 未分析Elasticsearch无法在排序中工作

ruby-on-rails - 如何测试 Rails 应用程序在生产环境中是否正常工作

ruby-on-rails - 添加具有 Rails 迁移的数据库列并基于另一列填充它

regex - 如何使用正则表达式只匹配字符串中多次出现的字母?

Ruby:尝试 object.send 带有参数的模块函数