how to delete tire index manually

1.5k Views Asked by At

If this is my model is the portion after_destroy() {tire.index.delete} the right way to use a callback to delete the index (which is out of sync with the db)?

If not how and where can I manually delete the index without using curl?

class Tag < ActiveRecord::Base
  attr_accessible :name

  include Tire::Model::Search
  include Tire::Model::Callbacks

  after_destroy() {tire.index.delete}

  def self.search(params)
    tire.search(load: true) do
      query { string params[:query]} if params[:query].present?
    end
  end

end
2

There are 2 best solutions below

0
On BEST ANSWER

You can start the ruby console where your code exists and run this there.

The index name for a model based tire approach takes plural form of model name as index name. eg: article.rb takes articles as index name.

Tire.index("<index_name>").delete

In your case it would be

Tire.index("tags").delete

Do note you can also use wildcards in the index name

Tire.index("*articles").delete

will delete any index which has index name that ends with "articles"

0
On

Yes, if you want to delete index manually without curl. You can make Rest-Client call to delete index. eg.

    generated_url = "http://#{host_name}:9200/#{index_name}"   
    RestClient.delete(generated_url) { |response, request, result| response }