我已经执行了 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 )
关于ruby-on-rails - elasticsearch-rails 空结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25879959/