I have this command and need to execute my program in python
curl -H 'Content-Type: application/x-ndjson' -XPOST '192.168.1.149:9200/shakespeare/doc/_bulk?pretty' --data-binary @file.json
I have this command and need to execute my program in python
curl -H 'Content-Type: application/x-ndjson' -XPOST '192.168.1.149:9200/shakespeare/doc/_bulk?pretty' --data-binary @file.json
use requests - HTTP for humans, which allows you to send any HTTP query you like
import requests
r = requests.post('192.168.1.149:9200/shakespeare/doc/_bulk?pretty', json=datadict)
print(r.text)
Try something like this:
import requests
import json
headers = {
'Content-Type': 'application/x-ndjson',
}
params = (('pretty', ''),)
data = open('file.json', 'rb').read()
response = requests.post('http://192.168.1.149:9200/shakespeare/doc/_bulk', headers=headers, params=params, data=data)
print(response.text)
Note: This is just a example according to your curl command.
Thankyou! Hope it helps you! :)