Peer-reviewed code snippets that anyone can edit
A wiki for useful code snippets
Command-line interface to the Apache Solr REST API

Solr Tool

A convenient command-line interface to Apache Solr, built around curl.

Requires xmllint - for pretty-printing the output. Requires Pygments - for syntax-highlighting the output.

Usage: solr BASE RESOURCE <ARGS>

BASE
is either the http:// base of a solr instance, or

one of the known shortcuts in the case statement.

RESOURCE
is added as $BASE/$RESOURCE for a full REST URL.

Remaining ARGS are passed to curl. Use -F key=value to POST form parameters.

Examples

solr local dataimport -F command=delta-import
solr local 'core0/select?q=solr'
solr http://localhost:8983/solr admin/cores -F command=RELOAD -F core=core0
solr local
#!/bin/bash
 
BASE="$1"; shift
RESOURCE="$1"; shift
 
case $BASE in
    dev) URL=http://eridanus.mihinternet.com:8983/solr ;;
    local) URL=http://localhost:8983/solr ;;
    http*) URL="$BASE" ;;
esac
 
[ -z $URL ] && { echo "No base URL specified."; exit 1; }
[ -z $RESOURCE ] && { echo "No resource specified."; exit 1; }
 
curl -s $URL/$RESOURCE "$@" | xmllint --format - | pygmentize -l xml -f console