I'm using the elasticsearch-rails gem and my order objects aren't being fully indexed on create. Here is my code:
after_commit on: [:create] do
begin
__elasticsearch__.index_document
rescue
Rails.logger.error "Elastic Search error indexing new order."
end
end
def self.index_orders
Order.all.import force: true
end
def as_indexed_json(options={})
as_json(only: [:id, :transaction_id, :purchase_order_number, :status], include: [:order_addresses])
end
When I call self.index_orders, everything works as expected. However, as orders are created, the after_commit function is not indexing the order_addresses as they are specified in the as_indexed_json function.
I haven't found anyone else with this issue. Does anyone know how to index the order_addresses inside an after_create?
UPDATE
I still haven't found a solution to this. Any help would be appreciated.