首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Elasticsearch + Tire + PaperClip :嵌套对象

Elasticsearch + Tire + PaperClip :嵌套对象
EN

Stack Overflow用户
提问于 2013-06-04 21:50:07
回答 1查看 228关注 0票数 1

我开始实现ElasticSearch来代替旧的自制搜索引擎。我迁移了代码的主要部分,但我必须呈现由回形针提供的url,并且我的结果中不能有正确的对象。

has_attached_file :内容,url:‘/系统/:附件/:id/:样式/:文件名’

代码语言:javascript
复制
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时得到的结果

代码语言:javascript
复制
{
  "element": {
    "properties": {
      "content": {
        "type": "string"
      },
      "name": {
        "type": "string"
      },
      "tags": {
        "properties": {
          "name": {
            "type": "string"
          }
        }
      }
    }
  }
}

我要给element.content.url打电话。但由于我不能将content转换为对象,因此此调用将失败。你能帮我找出我的代码中的错误之处吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-04 22:36:55

已解决。从代码中看,块似乎是被解释的。所以我换掉了

代码语言:javascript
复制
indexes :content, type: :object do
    indexes :url
end

通过

代码语言:javascript
复制
indexes :content { url: {type: :string}}

解决了问题

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16919648

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档