![](/img/trans.png)
[英]Tire::Search::SearchRequestFailed error about utf8
[英]Ruby: ElasticSearch + Tire error Tire::Search::SearchRequestFailed - IndexMissingException?
我想使用ElasticSearch + Tire來搜索存儲在MongoDB中的內容。
但是,當我嘗試執行搜索時,我收到以下錯誤:
SearchFtroller #index中的Tire :: Search :: SearchRequestFailed
404 : {"error":"IndexMissingException[[events] missing]","status":404}
根據我的理解,這告訴我事件中缺少索引,即使我在運行db:setup
時告訴它生成它們。
模型:
class Event
include Mongoid::Document
include Mongoid::Timestamps
include Tire::Model::Search
include Tire::Model::Callbacks
field :name, :type => String
field :description, :type => String
field :started_at => Time
field :ended_at => Time
def to_indexed_json
self.as_json
end
end
控制器:
def search
Event.tire.search(params[:q])
end
有關如何解決此問題的任何想法嗎?
......甚至更好,只需運行:
rake environment tire:import CLASS=Event FORCE=true
設置一個初始化程序(以下內容將在您的機器本地和onoku上使用盆景附加組件,以防萬一...):
# config/initializers/bonsai.rb
if ENV['BONSAI_INDEX_URL']
Tire.configure do
url "http://index.bonsai.io"
end
BONSAI_INDEX_NAME = ENV['BONSAI_INDEX_URL'][/[^\/]+$/]
else
app_name = Rails.application.class.parent_name.underscore.dasherize
BONSAI_INDEX_NAME = "#{app_name}-#{Rails.env}"
end
在您的模型中添加index_name
:
class Event
include Mongoid::Document
include Mongoid::Timestamps
include Tire::Model::Search
include Tire::Model::Callbacks
index_name BONSAI_INDEX_NAME
field :name, :type => String
field :description, :type => String
field :started_at => Time
field :ended_at => Time
def to_indexed_json
self.as_json
end
end
然后用rails c
打開你的Rails控制台並運行:
1.9.2p290 :001 >Event.create_elasticsearch_index
=> 200 : {"ok":true,"acknowledged":true}
1.9.2p290 :002 > Tire.index BONSAI_INDEX_NAME
1.9.2p290 :003 > import Event.all
1.9.2p290 :004?> refresh
1.9.2p290 :005?> end
你應該看到類似的東西:
MONGODB (0ms) ... ['system.namespaces'].find({})
MONGODB (0ms) ... ['events'].find({})
=> #<Tire::Index:0xca8fb18 @name="your-app-name-development",@response=200 : {"ok":true,"_shards":{"total":10,"successful":5,"failed":0}}>
1.9.2p290 :006 >
現在啟動rails並重試。
... 也可以看看 :
Event.index.import Event.all
這樣,所有記錄都被加載到內存中,序列化為JSON,並通過線路發送到ElasticSearch。 這個,以及之前的兩個解決方案,應該避免“IndexMissingException [[events] missing]”錯誤。
如果修改配置,可能會發生這種情況。 如果您定義了Tire.configure,請嘗試刪除它。
你有沒有索引你的事件模型? 你的場地模特? 彈性搜索也在尋找Venues指數
我有一個rake任務來重新索引我的模型
desc“Reindex活動”
task:reindex_events =>:環境做batch_size = 1000 count = batch_size Event.all.find_in_batches(:batch_size => batch_size) { |objects| puts "Count: " + count.to_s count += batch_size Event.index.import objects }
結束
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.