Skip to content

Instantly share code, notes, and snippets.

@nz
Last active January 27, 2026 19:05
Show Gist options
  • Select an option

  • Save nz/673027 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

Very useful --- thanks Nick!

@dynnamitt

Copy link
Copy Markdown

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

@dynnamitt

Copy link
Copy Markdown

and ..

!/bin/sh

at top of file

@nz

nz commented Feb 27, 2012

Copy link
Copy Markdown
Author

@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
Copy Markdown

Very useful gist, thanks.

@jeffrycopps

Copy link
Copy Markdown

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

SainathSharmadha commented Aug 23, 2016

Copy link
Copy Markdown

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
Copy Markdown

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

objectivePinta commented Dec 2, 2016

Copy link
Copy Markdown

@GrazingScientist

GrazingScientist commented Jan 17, 2018

Copy link
Copy Markdown

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

captainjackrana commented Feb 9, 2018

Copy link
Copy Markdown

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