1

古い自作の検索エンジンの代わりに、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

そして、ここにcurlでElasticsearchをクエリしたときの結果があります

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

電話する必要がありますelement.content.url。しかしcontent、オブジェクトに目を向けることができないため、この呼び出しは失敗します。私のコードで何が間違っているかを見つける方法を見つけるのを手伝ってくれませんか?

4

1 に答える 1

0

解決しました。コードを見ると、ブロックが解釈されているようです。なので交換しました

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

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

問題を解決しました

于 2013-06-04T14:36:55.023 に答える