简体   繁体   中英

Elasticsearch + Tire + PaperClip : Nested objects

I start implementing ElasticSearch in place of a old home-made search engine. I migrate the major part of the code, but I have to render a url provided by paperclip, and I cannot have the right object in my resulsts

has_attached_file :content, url: '/system/:attachment/:id/:style/:filename'

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

And here is the result I have when querying Elasticsearch with curl

{
  "element": {
    "properties": {
      "content": {
        "type": "string"
      },
      "name": {
        "type": "string"
      },
      "tags": {
        "properties": {
          "name": {
            "type": "string"
          }
        }
      }
    }
  }
}

I need to call element.content.url . But since I can't turn content to an object, this call will fail. Could you help me to find how to find what's wrong in my code?

Resolved. Looking in the code, block seems to be interpreted. So I replaced

indexes :content, type: :object do
    indexes :url
end

by

indexes :content { url: {type: :string}}

solved the problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM