【发布时间】:2019-10-09 13:50:03
【问题描述】:
我想生成一个自定义 json 行并将其与另一个行一起显示。我现在只能显示一个 json 行。我需要按顺序显示这两个。我正在使用curl data.json | jq '{"index": {"index": {}}} + .hits.hits[]' 将属性“索引”添加到属性“命中”
我尝试使用jq '.index + ._source' 进行管道传输,但这只是将属性连接到_source。我试过jq .index ._source,但这是一个错误。
我可以通过管道传输结果jq ._source 或jq .index 来选择_source 或.index。这将正确生成 json 行。没关系。现在我需要 .index,在 ._source 的每个 json 行之前。
我需要这样的结果:
{"index": {}}
{/* ._source json line*/}
{"index": {}}
{/* ._source json line*/}
and so on...
谢谢!
【问题讨论】:
-
这个答案应该会有所帮助:stackoverflow.com/a/45604500/4604579 但使用
.hits.hits[]而不是.[] -
我的坏@Val,错过了那个
-
请根据minimal reproducible example 指南修正问题。特别是,代表 jq 输入的有效 JSON 文本以及相应的预期结果会很有帮助。
标签: json elasticsearch jq jsonlines