我正在尝试使用两个模型elasticsearch
和account.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.rb
和showcase_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
有关如何解决此错误的任何想法?