Reputation: 3174
I'm using the elasticsearch-rails
gem with Rails 6
. I'm trying to index the return value of a carrierwave function asset_host
. I can index the file
function, but I'm not sure of the syntax to index the asset_host
method on the Uploader
object returned by `file.
From my model, I can access the function with the following code:
Asset.first.file.asset_host
I've added the asset_host
file to my mapping with this code:
indexes :file do
indexes :asset_host, type: "text"
end
And this is my attempt to add the method to the as_indexed_json
function which is where I'm having issues:
def as_indexed_json(options={})
as_json(methods: {file: [:asset_host]})
end
Here is the error I am getting with this code for as_indexed_json
when I try to reindex my documents:
TypeError ([:file, [:asset_host]] is not a symbol nor a string)
I guess this functionality isn't supported? Is there a workaround?
Upvotes: 1
Views: 117
Reputation: 8898
Seems like an as_json
problem. Maybe you could try
as_json(
only: [], # exclude all "normal" attributes
include: {file: {only: :asset_host}}
)
Upvotes: 0