Home > HowTo > solr index command

solr index command

Not sure if there is another better way to do it.
But I wrote this script to perform full or delta imports.
more details http://wiki.apache.org/solr/DataImportHandler

#!/bin/bash
# script to index Solr
# by Felipe Ferreira Sept 2013

TYPE=$1
DATE=`date +%d_%m_%y`
DATEFULL=`date +%H:%M:%S_%d_%m_%y`
LOG=”/var/log/solr/solr_import_${TYPE}_${DATE}.log”
LOGTMP=”/var/log/solr/solr_status_${DATE}.log”

URL=”http://:8080/solr/dataimport?command=status”

pt() {
echo -e $1
echo -e $1 >> $LOG
}

if [ $TYPE == “full” ]; then
pt “$DATEFULL – Starting full import”
URL=”http://:8080/solr/dataimport?command=full-import”
# CMD=”curl –location –no-buffer –fail –silent –output ${LOG} ‘${URL}'”
CMD=”curl –location –silent –no-buffer ‘${URL}’ >> $LOG”
pt “Executing $CMD”
CMD_E=`eval $CMD`
pt $CMD_E
elif [ $TYPE == “delta” ]; then
pt “$DATEFULL – Starting delta import”
URL=”http://:8080/solr/dataimport?command=delta-import”
#CMD=”curl –location –no-buffer –fail –silent –output ${LOG} ‘${URL}'”
CMD=”curl –location –silent –no-buffer ‘${URL}’ >> $LOG”
pt “Executing $CMD”
CMD_E=`eval $CMD`
pt $CMD_E
else
pt “ERROR – $TYPE not found, only delta or full,\n Usage: $0 delta/full”
fi

sleep 3

#check status after command
pt “$DATEFULL – Checking $TYPE status”
URL=”http://infofish2:9080/solrcadin/cadin/dataimport?command=status”
CMD=”curl –location –silent –no-buffer ‘${URL}’ > $LOGTMP”
pt “Executing $CMD”
CMD_E=`eval $CMD`
pt $CMD_E
CHECK=0
CHECK=`grep -c failed $LOGTMP`
if [ $CHECK -eq 0 ]; then
pt “OK – Command $TYPE executed with success!”
exit 0
else

pt “CRITICAL – Command $TYPE failed, solr did not index!”
pt “grep -c failed $LOGTMP”
pt “CHECK $CHECK”
exit 0
fi

Categories: HowTo Tags:
  1. No comments yet.
  1. No trackbacks yet.

VAMOVE *

*