title: AWS Elasticsearch: bulk insert using Python requests
body: <p>I have an index users. These are my documents:</p>
  <pre><code>doc1 = {&quot;user_id&quot;:1, &quot;name&quot;:&quot;first1 last1&quot;}
  doc2 = {&quot;user_id&quot;:2, &quot;name&quot;:&quot;first2 last2&quot;}
  </code></pre>
  <p>I'm trying to do a bulk insert using Python's requests</p>
  <pre><code>data_as_str = &quot;&quot;
  data_as_str += json.dumps({ &quot;_index&quot;: &quot;users&quot;}) + &quot;\n&quot;
  data_as_str += json.dumps(doc1) + &quot;\n&quot;
  data_as_str += json.dumps({ &quot;_index&quot;: &quot;users&quot;}) + &quot;\n&quot;
  data_as_str += json.dumps(doc2) + &quot;\n&quot;
  
  headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
  
  r = requests.post(&quot;https://ES_HOST/_bulk&quot;, auth=awsauth, headers=headers, data=data_as_str)
  </code></pre>
  <p>The error I get is illegal_argument_exception:</p>
  <p>Malformed action/metadata line [1], expected START_OBJECT but found [START_ARRAY]</p>
  <p>I've tried putting it inside a list and adding extra newlines, etc.</p>
  <p>EDIT:</p>
  <p>If I send json instead of data:</p>
  <pre><code>r = requests.post(bulkurl, auth=awsauth, headers=headers, json=data_as_str)
  </code></pre>
  <p>then the error is <strong>The bulk request must be terminated by a newline [\n]</strong></p>
  <p>But I do end it with a newline.</p>