[英]elasticsearch-rails empty results
我已經做了Comment.import
並返回0,這意味着在導入過程中沒有錯誤。
我已經做過Comment.__elasticsearch__.refresh_index!
這是我正在使用的模型:
require "datamapper_adapter"
class Comment
include DataMapper::Resource
include Elasticsearch::Model
property :id, Serial
property :email, String
property :author, String
property :description, String
property :created_at, DateTime
belongs_to :picture
validates_presence_of :email, :author, :description
settings index: { number_of_shards: 1 } do
mappings dynamic: 'false' do
indexes :id, analyzer: 'english', index_options: 'offsets'
indexes :author, analyzer: 'english', index_options: 'offsets'
indexes :description, analyzer: 'english', index_options: 'offsets'
end
end
def as_indexed_json(options={})
as_json.except("picture_id", "created_at", "email", "_persistence_state", "_repository", "_id")
end
end
而且我對elasticsearch的所有查詢都返回一個空數組作為命中。
curl -XPOST 'http://localhost:9200/comments/comment/_search?pretty
{
"took" : 35,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
我的數據庫中有數據,但我不知道它為什么永遠不會被過濾掉。 任何想法為什么會這樣? 這讓我瘋了
無論我做什么,點擊總是空的
你可以嘗試添加type:string
到indexes :description
和indexes :author
我還記得我有as_json的問題,對於舊的rails版本,它將包含root屬性。 嘗試將其設置為false,您可以全局或在as_json( root: false )
執行此as_json( root: false )
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.