Rails Elasticsearch错误:[400]找不到uri [// items]和方法[PUT]的处理程序

时间:2017-09-01 17:10:26

标签: ruby-on-rails ruby elasticsearch

我正在尝试使用两个模型elasticsearchaccount.rb来实施item.rb。帐户模型包含地址信息,项目模型包含可搜索项目。

我还使用gem geocoded来获取地址插入account.rb时的纬度和经度坐标。

通过以下设置我收到此错误:

Elasticsearch::Transport::Transport::Errors::BadRequest in ShowcaseController#index
[400] No handler found for uri [//items] and method [PUT]

分别在item.rbshowcase_controller.rb这两行:

Item.__elasticsearch__.client.indices.create \
@items = Item.all

item.rb的

require 'elasticsearch/model'

class Item < ApplicationRecord
  mount_uploader :image, ImageUploader
  belongs_to :category
  belongs_to :store

  include Elasticsearch::Model
  include Elasticsearch::Model::Callbacks

  settings index: { number_of_shards: 1, number_of_replicas: 0 } do
    mapping do
      indexes :location, type: 'geo_point'
    end
  end

  def location
    [latitude, longitude]
  end

  def self.search()
    __elasticsearch__.search(
        {
            query: {
                match_all: {}
            },
            sort: [{'_geo_distance' => {
                location: {
                    latitude: 0,
                    longitude: 0
                }
            }
                   }]
        }
    )
  end
end

Item.__elasticsearch__.client.indices.delete index: Item.index_name rescue nil


Item.__elasticsearch__.client.indices.create \
  index: Item.index_name,
  body: { settings: Item.settings.to_hash, mappings:  Item.mappings.to_hash }

Item.import

showcase_controller.rb

class ShowcaseController < ApplicationController
  def index
    @items = Item.all
  end

  private

  def front_params
    params.require(:front).permit(:title, :description, :price, :image, :location )
  end
end

有关如何解决此错误的任何想法?

0 个答案:

没有答案