[英]Indexing Method Results in ElasticSearch from Associated ActiveRecord Objects
[英]Indexing Method on Object Returned From Method - Elasticsearch
我在Rails 6
使用elasticsearch-rails
gem。 我正在尝试索引asset_host
函数asset_host
的返回值。 我可以索引file
函数,但我不确定在由 ` asset_host
返回的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)
我猜这个功能不受支持? 有解决方法吗?
似乎是as_json
问题。 也许你可以试试
as_json(
only: [], # exclude all "normal" attributes
include: {file: {only: :asset_host}}
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.