Last active
December 23, 2015 15:34
-
-
Save cwilper/d594491c1dad6d901b0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Dumps a subset of one Solr core and loads it into another one. | |
# | |
# WARNING: THIS DUMP AND LOAD IS LOSSY -- DO NOT USE IT FOR BACKUPS! | |
# In particular, multi-valued fields won't import in the target exactly as they were in the source. | |
# | |
# Before running, change the variables below as needed for your task. | |
# | |
# Set these as appropriate for your dump and load task | |
SOURCE_URL="http://localhost:8080/solr/core1" | |
TARGET_URL="http://localhost:8080/solr/core2" | |
ENCODED_QUERY="*%3A*" | |
ROWS=100 | |
# Determine list of field names to dump | |
FIELDS=$(curl -s "$SOURCE_URL/select?q=$ENCODED_QUERY&fl=*&wt=csv&rows=0" | sed 's/,_version_,/,/' | sed 's/,_version_//' | sed 's/_version_,//') | |
# Dump the results of the query as csv, without _version_ | |
curl -s "$SOURCE_URL/select?q=$ENCODED_QUERY&fl=$FIELDS&wt=csv&rows=$ROWS" > /tmp/solr-dump.csv | |
# Import the dump into the other solr core | |
curl "$TARGET_URL/update/csv?commit=true" --data-binary @/tmp/solr-dump.csv -H 'Content-type:text/plain; charset=utf-8' | |
# Finally, remove the dump file | |
rm /tmp/solr-dump.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment