我已经使用了这个ElasticSearch快照输出,并希望减少它以在单行上打印snapshot
和end_time_in_millis
属性的每个snapshot
值通过空间:
1429609790767 snapshot_1
1429681169896 snapshot_2
基本上是
的输出cat data | jq '.snapshots[].end_time_in_millis'
和cat data | jq '.snapshots[].snapshot'
但在一行上合并。
我在看map
,但无法知道如何应用它;还试着阅读this answer我试过了:
cat data | jq '.snapshots[] | map(. |= with_entries( select( .key == ( "snapshot") ) ) )'
但这会产生大量错误并输出null
。
数据:
{
"snapshots": [
{
"shards": {
"successful": 1,
"failed": 0,
"total": 1
},
"failures": [],
"snapshot": "snapshot_1",
"indices": [
"myindex1"
],
"state": "SUCCESS",
"start_time": "2015-04-21T09:45:47.041Z",
"start_time_in_millis": 1429609547041,
"end_time": "2015-04-21T09:49:50.767Z",
"end_time_in_millis": 1429609790767,
"duration_in_millis": 243726
},
{
"shards": {
"successful": 1,
"failed": 0,
"total": 1
},
"failures": [],
"snapshot": "snapshot_2",
"indices": [
"myindex1"
],
"state": "SUCCESS",
"start_time": "2015-04-22T05:36:02.333Z",
"start_time_in_millis": 1429680962333,
"end_time": "2015-04-22T05:39:29.896Z",
"end_time_in_millis": 1429681169896,
"duration_in_millis": 207563
}
]
}
答案 0 :(得分:8)
使用此过滤器:
.snapshots[] | "\(.end_time_in_millis) \(.snapshot)"
这为每个快照构建一个字符串,包括结束时间和快照名称。
请确保使用-r
选项获取原始输出。