我有这个ElasticSearch快照输出,并想将其降低到打印,在一行上,从各snapshot的的值 end_time_in_millis,并snapshot用空格分开的属性:
1429609790767 snapshot_1
1429681169896 snapshot_2
Run Code Online (Sandbox Code Playgroud)
基本上是输出
cat data | jq '.snapshots[].end_time_in_millis' 和cat data | jq '.snapshots[].snapshot'但在一条线上合并.
我在看,map但无法弄清楚如何应用它; 也读这个答案我尝试:
cat data | jq '.snapshots[] | map(. |= with_entries( select( .key == ( "snapshot") ) ) )'
Run Code Online (Sandbox Code Playgroud)
但这会产生大量错误和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
}
]
}
Run Code Online (Sandbox Code Playgroud)
Jef*_*ado 10
使用此过滤器:
.snapshots[] | "\(.end_time_in_millis) \(.snapshot)"
Run Code Online (Sandbox Code Playgroud)
这会为每个快照构建一个字符串,其中包含结束时间和快照名称.
只需确保使用该-r选项即可获得原始输出.
| 归档时间: |
|
| 查看次数: |
4575 次 |
| 最近记录: |