0

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.

Cannon Moyer
  • 3,014
  • 3
  • 31
  • 75
  • Dunno the answer, and IDK how invested are you in this gem already. But if just prototyping or if switching is not a big problem you might want to give a try with https://github.com/toptal/chewy – Greg Feb 21 '18 at 15:55
  • @meta I am currently running this in production and it's a bug that was reported to me. This entire implementation has been extremely difficult with limited documentation. – Cannon Moyer Feb 21 '18 at 15:57

0 Answers0