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