Elasticsearch + Tire + PaperClip: вложенные объекты

Начинаю внедрять ElasticSearch вместо старой самодельной поисковой системы. Я переношу большую часть кода, но мне нужно отобразить URL-адрес, предоставленный скрепкой, и я не могу иметь правильный объект в своих результатах.

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

И вот результат, который я получаю при запросе Elasticsearch с помощью curl

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

Мне нужно позвонить element.content.url. Но поскольку я не могу превратить content в объект, этот вызов завершится ошибкой. Не могли бы вы помочь мне найти, как найти ошибку в моем коде?


person Vincent    schedule 04.06.2013    source источник


Ответы (1)


Решено. Глядя в код, блок, кажется, интерпретируется. Поэтому я заменил

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

by

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

решил проблему

person Vincent    schedule 04.06.2013