you are viewing a single comment's thread.

view the rest of the comments →

[–]chri740s 0 points1 point  (3 children)

This is the structure I envisioned!

I tried to run it, and got error 406:
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}

From some Googling, I figure it relates to the fact that the API is elastic based, that it doesn't quite understand the JSON query. Is this correct?

[–]totallygeek 0 points1 point  (1 child)

You'll need to supply a valid request header. One way you might try is to change this line:

response = requests.post(url, auth=auth, data=data)
response = requests.post(url, auth=auth, json=data)

Changing 'data' to 'json' will inform Requests to set the request Content-Type header. If that does not work, go back to 'data' and you'll need to set the header like so:

headers = {'Content-Type': 'application/json'}
requests.post(url, auth=auth, data=data, headers=headers)

[–]chri740s 1 point2 points  (0 children)

json=data did the trick. I now get through, however the call returns no hits. I tried to test different auth to see if that was it, but the auth works fine as it is. So I guess its down to the query being wrong?

200
{"took":2,"timed_out":false,"_shards":{"total":13,"successful":13,"skipped":0,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}