【问题标题】:Indexing Method on Object Returned From Method - Elasticsearch从方法返回的对象的索引方法 - Elasticsearch
【发布时间】: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


    【解决方案1】:

    似乎是as_json 问题。也许你可以试试

    as_json(
      only: [],  # exclude all "normal" attributes
      include: {file: {only: :asset_host}}
    )
    

    【讨论】:

      猜你喜欢
      • 2018-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-14
      • 1970-01-01
      • 2020-03-06
      • 2015-12-20
      • 1970-01-01
      相关资源
      最近更新 更多