我已经在docker中安装了Elasticsearch。 我得到了像这样的弹性搜索的响应-
curl -XGET http://localhost:9200
{
"name" : "NXgYHOl",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "_na_",
"version" : {
"number" : "6.6.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "a9861f4",
"build_date" : "2019-01-24T11:27:09.439740Z",
"build_snapshot" : false,
"lucene_version" : "7.6.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
然后,我在rails
项目中对其进行配置。
宝石文件
gem 'elasticsearch-model'
gem 'elasticsearch-rails'
应用/模型
require 'elasticsearch/model'
class Movie < ApplicationRecord
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
end
Movie.import(force: true)
config / initilizers / elasticsearch.rb
config = {
host: "http://localhost:9200",
transport_options: {
request: { timeout: 5 }
}
}
if File.exists?("config/elasticsearch.yml")
config.merge!(YAML.load_file("config/elasticsearch.yml")[Rails.env].symbolize_keys)
end
Elasticsearch::Model.client = Elasticsearch::Client.new(config)
config / elasticsearch.yml
development: &default
host: 'http://localhost:9200'
transport_options:
request:
timeout: !!integer 300
test:
<<: *default
production:
host: 'http://localhost:9200'
transport_options:
request:
timeout: !!integer 300
出现错误:
未定义的方法“ params_encoder”,用于{“ timeout” => 300,:proxy => nil}:哈希
我不明白此错误。
答案 0 :(得分:0)
根据红宝石宝石的official docs,看来transport_options
不是一个选择。
但是它确实提到了request_timeout
选项,该选项应该起作用。
因此,将您的config/elasticsearch.yml
文件更改为以下内容:
development: &default
host: 'http://localhost:9200'
request_timeout: !!integer 300
test:
<<: *default
production:
host: 'http://localhost:9200'
request_timeout: !!integer 300