繁体   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