【发布时间】:2015-01-13 19:14:43
【问题描述】:
今天我开始阅读有关 elasticsearch 的内容,并尝试在我的 ruby on rails 应用程序中使用它。
所以我做了一些调整,就像我在示例中看到的那样:
我的模特:
class Service < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
end
我的控制器:
class ServicesController < ApplicationController
(...)
# GET /services/search
def search
@services = Service.search(params[:q]).records
render action: "index"
end
(...)
end
我的看法:
(...)
<%= form_tag search_services_path, method: 'get' do %>
<%= text_field_tag :q, params[:q] %>
<%= button_tag :search %>
<% end %>
(...)
我的路线:
Newapp::Application.routes.draw do
(...)
resources :services do
collection { get :search }
end
(...)
end
但是当我找到任何东西时,我总是收到 0(零)个结果。
其他人认为我试图这样做:
$ curl -XPOST 'localhost:9200/services/_search?pretty' -d '
{ "query": { "match_all": {} } }'
返回:
{
"took" : 2396,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
我需要做什么才能通过我的 rails 模型进行弹性搜索查找保存在我的数据库中的数据
感谢您的帮助!
【问题讨论】:
标签: ruby-on-rails database search elasticsearch