Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@smcpherson smcpherson commented Dec 15, 2010

Very useful --- thanks Nick!

@dynnamitt

This comment has been minimized.

Copy link

@dynnamitt dynnamitt commented Feb 9, 2012

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

@dynnamitt

This comment has been minimized.

Copy link

@dynnamitt dynnamitt commented Feb 9, 2012

and ..

!/bin/sh

at top of file

@nz

This comment has been minimized.

Copy link
Owner Author

@nz 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

This comment has been minimized.

Copy link

@jamespsterling jamespsterling commented Oct 27, 2015

Very useful gist, thanks.

@jeffrycopps

This comment has been minimized.

Copy link

@jeffrycopps jeffrycopps commented Dec 23, 2015

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

This comment has been minimized.

Copy link

@SainathSharmadha 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

This comment has been minimized.

Copy link

@qiqidone qiqidone commented Sep 27, 2016

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

This comment has been minimized.

Copy link

@objectivePinta objectivePinta commented Dec 2, 2016

@GrazingScientist

This comment has been minimized.

Copy link

@GrazingScientist 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

This comment has been minimized.

Copy link

@captainjackrana 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