![](/img/trans.png)
[英]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.