Posted By

Twain on 12/29/09


Tagged

cli solr


Versions (?)



Command-line interface to Solr REST API


Published in: Bash 



Website Promotion
DIRECTORY
is a crucial factor for all websites that need to gain better organic search engine rankings and increase website traffic.
Submitting your website as part of your Web Promotion strategy to our SEO friendly and high traffic Business Directory for review is an excellent way to gain a valuable backlink and increase your websites visibility online.

Submit Site


A convenient wrapper around curl to provide a command-line interface to Apache Solr.

It depends on curl to carry out the commands, xmllint to pretty-print the XML result, and Pygments to syntax-highlight the XML result.

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 makes $BASE/$RESOURCE the full REST URL.
  • ARGS are are passed to curl. Use -F key=value to POST form parameters.

Examples:

solr http://localhost:8983/solr admin/cores -F command=RELOAD -F core=core0
solr local admin/cores -F command=RELOAD -F core=core0
solr local dataimport -F command=delta-import
solr local core0/select?q=solr
solr example trunk/update -d '<delete><id>1</id></delete>'
Expand | Embed | Plain Text
  1. #!/bin/bash
  2.  
  3. BASE="$1"; shift
  4. RESOURCE="$1"; shift
  5.  
  6. case $BASE in
  7. example) URL=http://www.example.com:8983/solr ;;
  8. local) URL=http://localhost:8983/solr ;;
  9. http*) URL="$BASE" ;;
  10. esac
  11.  
  12. [ -z $URL ] && { echo "No base URL specified."; exit 1; }
  13. [ -z $RESOURCE ] && { echo "No resource specified."; exit 1; }
  14.  
  15. curl -s -H "Content-Type: text/xml" "$URL/$RESOURCE" "$@" | xmllint --format - | pygmentize -l xml -f console

Report this snippet 

You need to login to post a comment.