Reputation: 1848
I'm using Rails with Sunspot gem and Websolr for Solr hosting. Let's say I have a Solr indexed ActiveRecord model like this:
class User < ActiveRecord::Base
searchable do
text :name
end
end
Now I want to remove indexing from this model, so I just remove this indexing code (searchable block). Will the indexed data be removed automatically from Solr? I assume not and that I need to remove/reindex in manually. I can reindex everything like this:
Sunspot.index
Sunspot.commit
But reindexing my whole database will be slow. Is there another - faster way to stop indexing 1 model? I don't see any interface in Websolr to look through and delete records from the index and I can't seem to find any information on how to remove models from indexing with Sunspot.
Upvotes: 0
Views: 1188
Reputation: 7777
I can reindex everything like this:
No, you can't, if you need to reindex again then open Rails console by typing rails c
and then
=> Model.index
# User Load (15.6ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT $1 [["LIMIT", 50]]
# [2018-02-27 18:45:04 +0600] Start Indexing
# D, [2018-02-27T18:45:05.439714 #15296] DEBUG -- : SOLR Request (762.4ms) [ path=update parameters={} ]
And for the removing indexed data then try to the following
curl http://localhost:8982/solr/default/update?commit=true -d '<delete><query>*:*</query></delete>'
Let's describe on the url part
localhost
: is the hostname.8982
: port number where your Solr server running if you confusing what is your port number then open rails console and type this puts Sunspot.config.inspect
it will show your port number./solr/default/update
: this is the path where your command execute.?commit=true -d
: That is the instruction.'<delete><query>*:*</query></delete>'
: that is the method.I have found this here but it's not working for me because there are port number and path different, I have edited my own way and it's working perfectly.
I think it will help.
Upvotes: 0