Adriano Araujo
Adriano Araujo

Reputation: 21

"jq: error: Cannot index array with string" getting data from ElasticSearch results with jq

I trying to get the listaObjeto from the json.

This is an extract of my 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"
        }
      }
    ]
  }
}

Here is the error I'm getting :

jq '.hits.hits._source.listaObjeto' jq: error: Cannot index array with string

Upvotes: 2

Views: 1144

Answers (1)

Marcus
Marcus

Reputation: 3534

.hits.hits is an array, so you will need to add [] to map over it:

.hits.hits[]._source.listaObjeto

Upvotes: 5

Related Questions