1

I am having difficulties with this: all the following return 405, and I have no idea why:

    data = {
        "xxx" : "status",
        "value" : "incomplete"
    }
    headers = {'Content-type': 'application/json'}
    response = requests.post(f'http://localhost:9200/my_index', data=json.dumps(data)) 
    response = requests.post(f'http://localhost:9200/my_index', data=json.dumps(data), headers=headers) 
    response = requests.post(f'http://localhost:9200/my_index', json=data)
    response = requests.post(f'http://localhost:9200/my_index', json=data, headers=headers) 

NB I have also tried with "http://localhost:9200/my_index/_doc" instead: they all get 406.

ES is definitely running, I am able to use Postman, and curl at the CLI.

requests.put with the above attempts (ending ".../_doc/1") gets either 406 or 401, except for one of the above:

response = requests.put(f'http://localhost:9200/my_index/_doc/2', data=json.dumps(data), headers=headers)

... which works (201 or 200 depending on whether the index already exists).

OS is Linux Mint 20. ES is 7.16.3.

mike rodent
  • 14,126
  • 11
  • 103
  • 157

2 Answers2

0

According to the docs, you must put _doc after the index name:

PUT /<target>/_doc/<_id>

POST /<target>/_doc/

You can choose whether Elastic will create the id for you, or you can also specify an id.

Index API

Netanel Malka
  • 346
  • 4
  • 11
0

Try adding "accept":"application/json" to your headers.

Justin
  • 4,461
  • 22
  • 87
  • 152