我已经执行了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" : [ ]
}
}我的数据库中有数据,但我不知道为什么它从来不会被过滤。你知道为什么会发生这种情况吗?这快把我逼疯了
不管我怎么做,点击总是空的
发布于 2015-08-18 21:45:25
您可以尝试将type:string添加到indexes :description和indexes :author中吗
我还记得我在使用as_json时遇到了问题,对于较老的rails版本,它将包含根属性。尝试将其设置为false,您可以全局或在as_json( root: false )中执行此操作
https://stackoverflow.com/questions/25879959
复制相似问题