Skip to content

Instantly share code, notes, and snippets.

@nz
Last active February 12, 2024 10:55
Show Gist options
  • Star 69 You must be signed in to star a gist
  • Fork 17 You must be signed in to fork a gist
  • Save nz/673027 to your computer and use it in GitHub Desktop.
Save nz/673027 to your computer and use it in GitHub Desktop.
Delete all documents in a Solr index using curl
# http://wiki.apache.org/solr/FAQ#How_can_I_delete_all_documents_from_my_index.3F
# http://wiki.apache.org/solr/UpdateXmlMessages#Updating_a_Data_Record_via_curl

curl "http://index.websolr.com/solr/a0b1c2d3/update?commit=true" -H "Content-Type: text/xml" --data-binary '<delete><query>*:*</query></delete>'

I'm amused at the traction this little gist is getting on Google! I would be remiss not to point out that six+ years later I'm still helping thousands of companies on a daily basis with their search index management, by providing managed Solr as a service over at Websolr, and hosted Elasticsearch at Bonsai. Check us out if you'd like an expert helping hand at Solr and Elasticsearch hosting, ops and support!

@smcpherson
Copy link

Very useful --- thanks Nick!

@dynnamitt
Copy link

You need "?commit=true" at end of url..

@dynnamitt
Copy link

and ..

!/bin/sh

at top of file

@nz
Copy link
Author

nz commented Feb 27, 2012

@dynnamitt: The commit is indeed useful; this command assumes autoCommit is set. Also, it's meant to be copied and pasted into a shell -- but by all means include the shebang and set u+x for a standalone script :)

@jamespsterling
Copy link

Very useful gist, thanks.

@jeffrycopps
Copy link

Fire this in the browser
For deletion:
http://host:port/solr/core/update?stream.body=:&commit=true
For schema reload:
http://host:port/solr/admin/cores?action=RELOAD&core=core
Replace
host: Host name
port: Port number
core: Core Name

@SainathSharmadha
Copy link

SainathSharmadha commented Aug 23, 2016

Through curl :

curl http://host:port/solr/core_name/update?commit=true -H "Content-Type: text/xml" --data-binary `'<delete><query>*:*</query></delete>'`

Through browser :

http://host:port/solr/core_name/update?commit=true&stream.body=<delete><query>*:*</query></delete>

@qiqidone
Copy link

single core:
curl http://localhost:8080/solr/update?commit=true -H "Content-Type: text/xml" --data-binary ':'
multiple core:
curl http://localhost:8080/solr/core_name/update?commit=true -H "Content-Type: text/xml" --data-binary ':'

@objectivePinta
Copy link

objectivePinta commented Dec 2, 2016

@GrazingScientist
Copy link

GrazingScientist commented Jan 17, 2018

The command by objectivePinta is shut off at least in Solr version 7.2.0 (in the out of the box configuration). However, the curl - solution of SainathSharmadha worked (for me) in this version.

@captainjackrana
Copy link

captainjackrana commented Feb 9, 2018

Solr version 7.2.0 doesn't allow stream body anymore.
However, SainathSharmadha code will work by using binary data type.
If you're using the Post tool provided by solr:
bin/post -c core_name -type text/xml -out yes -d $'<delete><query>*:*</query></delete>'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment