title: Parsing Elasticsearch json output in Python
body: <p>I am parsing data from Elasticsearch index and have received the data in json format as follows:</p>
  
  <pre><code>{
      "_shards": {
          "failed": 0,
          "skipped": 0,
          "successful": 5,
          "total": 5
      },
      "hits": {
          "hits": [
              {
                  "_id": "wAv4u2cB9qH5eo0Slo9O",
                  "_index": "homesecmum",
                  "_score": 1.0870113,
                  "_source": {
                      "image": "0000000028037c08_1544283640.314629.jpg"
                  },
                  "_type": "dataRecord"
              },
              {
                  "_id": "wwv4u2cB9qH5eo0SmY8e",
                  "_index": "homesecmum",
                  "_score": 1.0870113,
                  "_source": {
                      "image": "0000000028037c08_1544283642.963721.jpg"
                  },
                  "_type": "dataRecord"
              },
              {
                  "_id": "wgv4u2cB9qH5eo0SmI8Z",
                  "_index": "homesecmum",
                  "_score": 1.074108,
                  "_source": {
                      "image": "0000000028037c08_1544283640.629583.jpg"
                  },
                  "_type": "dataRecord"
              }
          ],
          "max_score": 1.0870113,
          "total": 5
      },
      "timed_out": false,
      "took": 11
  }
  </code></pre>
  
  <p>I am trying to extract only the image parameter from json data and store it as an array.  I tried the following:</p>
  
  <pre><code>for result in res['hits']['hits']:
      post = result['_source']['image']
      print(post)
  </code></pre>
  
  <p>and this:</p>
  
  <pre><code>respars = json.loads(res['hits']['hits'][0]['_source'])['image']
  print(json.dumps(respars, indent=4, sort_keys = True))
  </code></pre>
  
  <p>Both these throws an error:</p>
  
  <pre><code>TypeError: byte indices must be integers or slices, not str
  </code></pre>
  
  <p>I am sure similar problems were raised earlier here, but I couldn't get through this error. How can I fix it?</p>