我开始实现ElasticSearch来代替旧的自制搜索引擎。我迁移了代码的主要部分,但我必须呈现由回形针提供的url,并且我的结果中不能有正确的对象。
has_attached_file :内容,url:‘/系统/:附件/:id/:样式/:文件名’
mapping do
indexes :name
indexes :description
indexes :tags do
indexes :name, type: :string
end
indexes :content, type: :object do
indexes :url
end
end
def to_indexed_json
{
name: name,
description: description,
tags: tags.map { |tag| { name: tag.name }},
content: content_url_json
}.to_json
end这是我使用curl查询Elasticsearch时得到的结果
{
"element": {
"properties": {
"content": {
"type": "string"
},
"name": {
"type": "string"
},
"tags": {
"properties": {
"name": {
"type": "string"
}
}
}
}
}
}我要给element.content.url打电话。但由于我不能将content转换为对象,因此此调用将失败。你能帮我找出我的代码中的错误之处吗?
发布于 2013-06-04 22:36:55
已解决。从代码中看,块似乎是被解释的。所以我换掉了
indexes :content, type: :object do
indexes :url
end通过
indexes :content { url: {type: :string}}解决了问题
https://stackoverflow.com/questions/16919648
复制相似问题