我只是按照本教程将弹性搜索添加到我的应用程序中。
我在 Windows 8 系统上工作,并且安装了 elasticsearch。但是当我尝试在我的应用程序中搜索某些内容时,它什么也找不到。
在教程中,他们说我可以使用 rails 控制台查看搜索是否有效。
我安装了 searchkick gem 并运行 bundle install。
我在 Ticket 类中添加了 searchkick。
class Ticket < ActiveRecord::Base
searchkick
# ...
end
我将 Ticket 类添加到索引中
rake searchkick:reindex CLASS=Book
当我尝试在 rails 控制台中搜索某些内容时,它什么也没找到。
irb(main):001:0> results = Ticket.search("computer")
Ticket Search (103.0ms)
curl http://lvh.me:9200/tickets_development/_search?pretty -d '{
"query": {
"dis_max": {
"queries": [
{
"match": {
"_all": {
"query": "computer",
"operator": "and",
"boost": 10,
"analyzer": "searchkick_search"
}
}
},
{
"match": {
"_all": {
"query": "computer",
"operator": "and",
"boost": 10,
"analyzer": "searchkick_search2"
}
}
},
{
"match": {
"_all": {
"query": "computer",
"operator": "and",
"boost": 1,
"fuzziness": 1,
"max_expansions": 3,
"analyzer": "searchkick_search"
}
}
},
{
"match": {
"_all": {
"query": "computer",
"operator": "and",
"boost": 1,
"fuzziness": 1,
"max_expansions": 3,
"analyzer": "searchkick_search2"
}
}
}
]
}
},
"size": 100000,
"from": 0,
"fields": []
}'
=> #<Searchkick::Results:0x6ec5de8 ,
@klass=Ticket(
id: integer,
name: string,
client: string,
archived: boolean,
created_at: datetime,
updated_at: datetime
)
@response={
"took"=> 90,
"timed_out"=> false,
"_shards"=> {
"total"=> 5,
"successful"=> 5,
"failed"=> 0
},
"hits"=> {
"total"=> 0,
"max_score"=> nil,
"hits"=> []
}
},
@options={
:page=>1,
:per_page=>100000,
:padding=>0,
:load=>true,
:includes=>nil,
:json=>false
} > irb(main):002:0> results.map(&:name) => []