“ jq:错误:无法使用字符串索引数组”使用jq从ElasticSearch结果获取数据

时间:2019-03-26 15:51:22

标签: bash jq

我试图从json中获取listaObjeto

这是我的json的摘录:

{
  "took": 42,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 11.2367325,
    "hits": [
      {
        "_index": "provflogs-2019.03.26",
        "_type": "Portal",
        "_id": "SQGEumkBYgyBeVm_SiGe",
        "_score": 11.2367325,
        "_source": {
          "siglaSistema": "SRPO",
          "dataPesquisa": "2019-03-26T12:00:25.896-0300",
          "ipRequisitante": "104.238.179.249",
          "listaObjeto": [
            "UB711395572YP",
            "OG461051611BR",
            "RG968790315CN"
          ],
          "loginUsuario": "USER1",
          "metodoRequisitado": "buscaEventos"
        }
      }
    ]
  }
}

这是我遇到的错误:

  

jq'.hits.hits._source.listaObjeto'jq:错误:无法索引数组   字符串

1 个答案:

答案 0 :(得分:3)

.hits.hits是一个数组,因此您需要添加[]才能在其上进行映射:

.hits.hits[]._source.listaObjeto