Assuming you want CSV output:
$ jq -r -f script file "collection1-stored","collection1-stored-conf1","shard1:core_node2","collection1-stored_shard1_replica_n1","servername1:8983_solr" "collection2-multi","collection2-multi-conf2","shard1:core_node3","collection2-multi_shard1_replica_n1","servername1:8983_solr" "collection2-multi","collection2-multi-conf2","shard1:core_node4","collection2-multi_shard1_replica_n2","servername2:8983_solr" "collection4-multi-multi1","collection4-multi-multi-conf4","shard1:core_node5","collection4-multi-multi1_shard1_replica_n2","servername1:8983_solr" "collection4-multi-multi1","collection4-multi-multi-conf4","shard1:core_node8","collection4-multi-multi1_shard1_replica_n6","servername2:8983_solr" "collection4-multi-multi1","collection4-multi-multi-conf4","shard2:core_node3","collection4-multi-multi1_shard2_replica_n1","servername1:8983_solr" "collection4-multi-multi1","collection4-multi-multi-conf4","shard2:core_node7","collection4-multi-multi1_shard2_replica_n4","servername2:8983_solr" "collection3-multi","collection3-multi-conf3","shard1:core_node7","collection3-multi_shard1_replica_n1","servername2:8983_solr" "collection3-multi","collection3-multi-conf3","shard1:core_node5","collection3-multi_shard1_replica_n2","servername1:8983_solr" ... where script is
.cluster.collections | to_entries[] | [.key, .value.configName] as [$collection, $config] | .value.shards | to_entries[] | .key as $shard | .value.replicas | to_entries[] | [.key, .value.core, .value.node_name] as [$replica, $core, $node] | [$collection, $config, $shard + ":" + $replica, $core, $node] | @csv This is essentially a triple loop, where...
- The outer loop is iterating over the
.cluster.collectionsentries, setting$collectionand$configto the collection's key and the.configNameattribute of the collection, respectively. - The second loop is iterating over the collection's shard entries, setting
$shardto the shard's key. - The inner loop then iterates over the shard's replicas, producing an array with the needed information, i.e., the collection name, the configuration name, the shard name concatenated with the replica name, and finally, the replica's core and node name.
The arrays produced by the inner loop are passed through @csv to be converted to CSV records. If you want to instead use a comma and space as the delimiter for the outputted fields, replace @csv with join(", ").
See also:
- Documentation for
to_entries.