Last active
May 1, 2018 03:06
-
-
Save zerebral/9e60bd64ff21abb712575fac2d63afbb to your computer and use it in GitHub Desktop.
Useful Solr Commands
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
Pre-requisites - | |
1. You'd need Ruby installed on the host(rvm.io) | |
2. Set the solr host env variable | |
export SOLR_HOST=10.68.77.13:8983 | |
3. Set the collection name env var | |
export SOLR_COLLECTION=<your collection name> | |
DROP the Solr Collection | |
curl "http://$SOLR_HOST/solr/admin/collections?action=DELETE&name=$SOLR_COLLECTION" | |
CREATE Solr Collection - | |
curl "http://$SOLR_HOST/solr/admin/collections?action=CREATE&name=$SOLR_COLLECTION&numShards=24&replicationFactor=3&maxShardsPerNode=3&collection.configName=$SOLR_COLLECTION" | |
Create collection on selected nodes - | |
curl "http://$SOLR_HOST/solr/admin/collections?action=CREATE&name=$SOLR_COLLECTION&numShards=16&replicationFactor=1&maxShardsPerNode=3&collection.configName=$SOLR_COLLECTION&createNodeSet=10.68.77.13:8983_solr,10.68.77.14:8983_solr,10.68.77.15:8983_solr,10.68.77.16:8983_solr,10.68.77.17:8983_solr,10.68.77.18:8983_solr,10.68.77.19:8983_solr,10.68.77.20:8983_solr,10.68.77.45:8983_solr,10.68.77.46:8983_solr,10.68.77.47:8983_solr,10.68.77.48:8983_solr,10.68.77.49:8983_solr,10.68.77.50:8983_solr,10.68.77.51:8983_solr,10.68.77.52:8983_solr" | |
List all solr shards - | |
curl "http://$SOLR_HOST/solr/admin/collections?action=clusterstatus&wt=json" | tr -d '\n' | SOLR_COLLECTION=$SOLR_COLLECTION ruby -e 'require "json"; puts JSON.parse(STDIN.gets)["cluster"]["collections"][ENV["SOLR_COLLECTION"]]["shards"].keys' | |
Split all shards - | |
curl "http://$SOLR_HOST/solr/admin/collections?action=clusterstatus&wt=json" | tr -d '\n' | SOLR_COLLECTION=$SOLR_COLLECTION ruby -e 'require "json"; puts JSON.parse(STDIN.gets)["cluster"]["collections"][ENV["SOLR_COLLECTION"]]["shards"].keys' | while read LINE; do curl "http://$SOLR_HOST/solr/admin/collections?action=SPLITSHARD&collection=$SOLR_COLLECTION&shard=$LINE"; done | |
Delete a shard for the collection - | |
curl "http://$SOLR_HOST/solr/admin/collections?action=DELETESHARD&shard=shard_name&collection=$SOLR_COLLECTION" | |
Add replica to all existing shards - | |
curl "http://$SOLR_HOST/solr/admin/collections?action=clusterstatus&wt=json" | tr -d '\n' | SOLR_COLLECTION=$SOLR_COLLECTION ruby -e 'require "json"; puts JSON.parse(STDIN.gets)["cluster"]["collections"][ENV["SOLR_COLLECTION"]]["shards"].keys' | while read LINE; do curl "http://$SOLR_HOST/solr/admin/collections?action=ADDREPLICA&collection=$SOLR_COLLECTION&shard=$LINE"; done | |
Delete 12 replica for shard1 for the collection - | |
curl "http://$SOLR_HOST/solr/admin/collections?action=DELETEREPLICA&collection=$SOLR_COLLECTION&shard=shard1&count=6" | |
Delete replica for all for all shards for the collection - | |
curl "http://$SOLR_HOST/solr/admin/collections?action=clusterstatus&wt=json" | tr -d '\n' | SOLR_COLLECTION=$SOLR_COLLECTION ruby -e 'require "json"; puts JSON.parse(STDIN.gets)["cluster"]["collections"][ENV["SOLR_COLLECTION"]]["shards"].keys' | while read LINE; do curl "http://$SOLR_HOST/solr/admin/collections?action=DELETEREPLICA&collection=$SOLR_COLLECTION&shard=$LINE&count=8"; done | |
List leader distribution on available nodes - | |
curl "http://$SOLR_HOST/solr/admin/collections?action=clusterstatus&wt=json" | tr -d '\n' | SOLR_COLLECTION=$SOLR_COLLECTION ruby -e 'require "json"; JSON.parse(STDIN.gets)["cluster"]["collections"][ENV["SOLR_COLLECTION"]]["shards"].each{|k,v| v["replicas"].select{|k,v| 1 == 1}.values.map{|x| printf "%s, %s, %s\n", k, x["node_name"], x["leader"] == "true"}}' | grep "false" | cut -f 2 -d, | sort | uniq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment