簡體   English   中英

從方法返回的對象的索引方法 - Elasticsearch

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM