0
我有一个返回哈希方法:在轮胎映射块访问方法/ elasticsearch
def image_hash
images = {
small: 'http://www.example.com/image1.png',
medium: 'http://www.example.com/image2.png'
}
end
我需要索引它作为轮胎加载ActiveModel映射的一部分,但我不能让它与合作indexes
方法中的as:
选项。
的问题是,我需要重新定义它为图片(这是另一个模型法),所以我想它像这样:
indexes :image_hash, as: :images do
indexes :small, type: 'string', include_in_all: false
end
但没有被正确创建索引。
我知道methods
选项为to_indexed_json
方法:
def to_indexed_json
to_json(methods: [:image_hash])
end
其中一期工程。但我无法看到如何在该块中重新定义它,而无需从头开始重新创建整个JSON对象。它也看起来像是完全使用mapping
块为索引的JSON。
任何帮助,将不胜感激。