como faço para que o jq receba json assim:
{
"responseHeader":{
"status":0,
"QTime":1
},
"cluster":{
"collections":{
"collection1-stored":{
"pullReplicas":"0",
"configName":"collection1-stored-conf1",
"replicationFactor":1,
"router":{
"name":"compositeId"
},
"nrtReplicas":1,
"tlogReplicas":"0",
"shards":{
"shard1":{
"range":"80000000-7fffffff",
"state":"active",
"replicas":{
"core_node2":{
"core":"collection1-stored_shard1_replica_n1",
"node_name":"servername1:8983_solr",
"type":"NRT",
"state":"active",
"leader":"true",
"force_set_state":"false",
"base_url":"http://servername1:8983/solr"
}
},
"health":"GREEN"
}
},
"health":"GREEN",
"znodeVersion":3,
"creationTimeMillis":1727780823546
},
"collection2-multi":{
"pullReplicas":"0",
"configName":"collection2-multi-conf2",
"replicationFactor":2,
"router":{
"name":"compositeId"
},
"nrtReplicas":2,
"tlogReplicas":"0",
"shards":{
"shard1":{
"range":"80000000-7fffffff",
"state":"active",
"replicas":{
"core_node3":{
"core":"collection2-multi_shard1_replica_n1",
"node_name":"servername1:8983_solr",
"type":"NRT",
"state":"active",
"leader":"true",
"force_set_state":"false",
"base_url":"http://servername1:8983/solr"
},
"core_node4":{
"core":"collection2-multi_shard1_replica_n2",
"node_name":"servername2:8983_solr",
"type":"NRT",
"state":"active",
"force_set_state":"false",
"base_url":"http://servername2:8983/solr"
}
},
"health":"GREEN"
}
},
"health":"GREEN",
"znodeVersion":5,
"creationTimeMillis":1727780813821,
"aliases":["collection2-multi-query","collection2-multi-upd"]
},
"collection4-multi-multi1":{
"pullReplicas":"0",
"configName":"collection4-multi-multi-conf4",
"replicationFactor":2,
"router":{
"name":"compositeId"
},
"nrtReplicas":2,
"tlogReplicas":"0",
"shards":{
"shard1":{
"range":"80000000-ffffffff",
"state":"active",
"replicas":{
"core_node5":{
"core":"collection4-multi-multi1_shard1_replica_n2",
"node_name":"servername1:8983_solr",
"type":"NRT",
"state":"active",
"force_set_state":"false",
"base_url":"http://servername1:8983/solr"
},
"core_node8":{
"core":"collection4-multi-multi1_shard1_replica_n6",
"node_name":"servername2:8983_solr",
"type":"NRT",
"state":"active",
"leader":"true",
"force_set_state":"false",
"base_url":"http://servername2:8983/solr"
}
},
"health":"GREEN"
},
"shard2":{
"range":"0-7fffffff",
"state":"active",
"replicas":{
"core_node3":{
"core":"collection4-multi-multi1_shard2_replica_n1",
"node_name":"servername1:8983_solr",
"type":"NRT",
"state":"active",
"leader":"true",
"force_set_state":"false",
"base_url":"http://servername1:8983/solr"
},
"core_node7":{
"core":"collection4-multi-multi1_shard2_replica_n4",
"node_name":"servername2:8983_solr",
"type":"NRT",
"state":"active",
"force_set_state":"false",
"base_url":"http://servername2:8983/solr"
}
},
"health":"GREEN"
}
},
"health":"GREEN",
"znodeVersion":7,
"creationTimeMillis":1727780770838,
"aliases":["collection4-multi-multi"]
},
"collection3-multi":{
"pullReplicas":"0",
"configName":"collection3-multi-conf3",
"replicationFactor":2,
"router":{
"name":"compositeId"
},
"nrtReplicas":2,
"tlogReplicas":"0",
"shards":{
"shard1":{
"range":"80000000-7fffffff",
"state":"active",
"replicas":{
"core_node7":{
"core":"collection3-multi_shard1_replica_n1",
"node_name":"servername2:8983_solr",
"type":"NRT",
"state":"active",
"force_set_state":"false",
"base_url":"http://servername2:8983/solr"
},
"core_node5":{
"core":"collection3-multi_shard1_replica_n2",
"node_name":"servername1:8983_solr",
"type":"NRT",
"state":"active",
"leader":"true",
"force_set_state":"false",
"base_url":"http://servername1:8983/solr"
}
},
"health":"GREEN"
}
},
"health":"GREEN",
"znodeVersion":6,
"creationTimeMillis":1727780768553,
"aliases":["collection3-multi-index","collection3-multi-query"]
}
}
}
}
e gerar esta saída:
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
usando o formatador jq.
Resumindo, preciso obter para cada nome de coleção e para cada um de seus fragmentos e para cada uma de suas réplicas, uma linha contendo o nome da coleção, o valor configName, o nome do núcleo, o valor do núcleo e o valor node_name.
Só consegui chegar ao primeiro nível filtrando como:
jq ".cluster.collections"
Obrigado
Supondo que você queira uma saída CSV:
... onde
script
estáEste é essencialmente um loop triplo, onde...
.cluster.collections
entradas, definindo$collection
e$config
para a chave da coleção e o.configName
atributo da coleção, respectivamente.$shard
a chave do fragmento.Os arrays produzidos pelo loop interno são passados
@csv
para serem convertidos em registros CSV. Se você quiser usar uma vírgula e um espaço como delimitador para os campos de saída, substitua@csv
porjoin(", ")
.Veja também:
to_entries
.