jeudi 19 janvier 2017

Gem Chewy update_index observer not working in rails app

I am using Elasticsearch 5.1 and gem Chewy, Import works perfectly while delete -> create -> import records. But while I try to add the observer in my model it's not updating the index. Did not found any clue how can I fix this or trace my problem.

I tried the following code snippet for the observer

class Product < ActiveRecord::Base
   update_index(ProductsIndex::Product) { self }
end

OR

class Product < ActiveRecord::Base
   update_index('products#product') { self }
end

I am using strategy as :urgent and the following mappings

class ProductsIndex < Chewy::Index

   settings analysis: {
         analyzer: {
           case_insensitive: {
             tokenizer: "keyword",
             filter: ["lowercase"]
           },

           lowercase_space_analyzer: {
             type: "custom",
             tokenizer: "whitespace",
             filter: ["synonym", "lowercase"]
           }
         }
       }

  define_type Product.includes(:job) do
     default_import_options batch_size: 100, bulk_size: 10.megabytes, refresh: true
     field :title, :heading, :ingress, :description, :job_language
     field :location, value: ->(product) { (product.location||"") }
     field :company_name, value: ->(product) { product.job.company.name }
     ........    
  end

end

Product class using single table inheritance and has some child class as following

class Product::Norway < Product
   ......
end

When I create/update Product nothing happen, how can I get ride of this?

Aucun commentaire:

Enregistrer un commentaire