【发布时间】:2021-01-30 17:00:26
【问题描述】:
我将elasticsearch-rails gem 与Rails 6 一起使用。我正在尝试索引载波函数asset_host 的返回值。我可以索引file 函数,但我不确定在`file 返回的Uploader 对象上索引asset_host 方法的语法。
从我的模型中,我可以使用以下代码访问该函数:
Asset.first.file.asset_host
我已使用以下代码将asset_host 文件添加到我的映射中:
indexes :file do
indexes :asset_host, type: "text"
end
这是我尝试将方法添加到我遇到问题的as_indexed_json 函数:
def as_indexed_json(options={})
as_json(methods: {file: [:asset_host]})
end
当我尝试重新索引我的文档时,使用此代码 as_indexed_json 时出现以下错误:
TypeError ([:file, [:asset_host]] is not a symbol nor a string)
我猜这个功能不被支持?有解决办法吗?
【问题讨论】:
标签: ruby-on-rails ruby elasticsearch elasticsearch-rails