Reputation: 11134
I was trying to index some data with elastic search, and faced a strange behavior.
If my code is:
import requests
#data = {'key': 'value'}
data = {'v': 'pf'}
#data = generate_document()
print(data)
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
r = requests.post('http://localhost:9200/qa/_doc', data=json.dumps(data), headers=headers)
print(r.status_code)
I get 201
as response code.
But if I have data = {'va': 'pf'}
, for some reason I get 400
status code.
Why do these weird things happen?
Basically I want to randomly generate data
and index it. Most of the time it throws 400
. But regular things like data = {"key": "value"}
works.
Upvotes: 0
Views: 194
Reputation: 2133
Likely the status code 400 could have multiple causes:
There may be others.
Upvotes: 1
Reputation: 910
Try:
import requests
#data = {'key': 'value'}
data = {'v': 'pf'}
#data = generate_document()
print(data)
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
r = requests.post('http://localhost:9200/qa/_doc', json=data, headers=headers)
Upvotes: 1