gpt4 book ai didi

ruby-on-rails - Elasticsearch::Transport::Transport::Errors::BadRequest [400] 创建索引时

转载 作者:数据小太阳 更新时间:2023-10-29 07:55:05 26 4
gpt4 key购买 nike

在我的 Rails 应用程序中,安装了“elasticsearch-model”和“elasticsearch-rails”gems,elasticsearch (v5.1.1) 在默认端口上运行,模型如下所示

class Article
include Mongoid::Document
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks

field :title, type: String
field :author, type: String

index_name "articles-#{Rails.env}"
end

初始化器是这样的

Elasticsearch::Model.client = Elasticsearch::Client.new host: ENV['ELASTICSEARCH_URL'] || "http://localhost:9200/"

当我尝试导入或创建索引时

Article.import force:true
Article.__elasticsearch__.create_index! force: true

我得到以下错误

 Elasticsearch::Transport::Transport::Errors::BadRequest: [400] No handler found for uri [//articles-development] and method [DELETE]
from /Users/bgr/.rvm/gems/ruby-2.3.0/gems/elasticsearch-transport-1.0.17/lib/elasticsearch/transport/transport/base.rb:201:in `__raise_transport_error'
from /Users/bgr/.rvm/gems/ruby-2.3.0/gems/elasticsearch-transport-1.0.17/lib/elasticsearch/transport/transport/base.rb:312:in `perform_request'
from /Users/bgr/.rvm/gems/ruby-2.3.0/gems/elasticsearch-transport-1.0.17/lib/elasticsearch/transport/transport/http/faraday.rb:20:in `perform_request'
from /Users/bgr/.rvm/gems/ruby-2.3.0/gems/elasticsearch-transport-1.0.17/lib/elasticsearch/transport/client.rb:128:in `perform_request'

最佳答案

经过一些调查,问题出在我的初始化程序上。它在更改主机后工作。

Elasticsearch::Model.client = Elasticsearch::Client.new host: ENV['ELASTICSEARCH_URL'] || "localhost:9200"

更新显然该配置适用于 Elasticsearch 2.4.x。

关于ruby-on-rails - Elasticsearch::Transport::Transport::Errors::BadRequest [400] 创建索引时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41514864/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com