We are looking into a Python library Elasticsearch Python Client
, and its official online document contains the below example for ingesting data into Elastic.
We hope to make the ingest action idempotent, so we wonder whether the library's index()
method uses PUT
or POST
.
Please also point out if we should investigate something else for the idempotent feature. We are new to Elasticsearch and its Python libraries, so we highly appreciate any hints and suggestions.
Details:
This reference says:
The PUT Method
The difference between POST and PUT is that PUT requests are idempotent. ...
The example in the official online document:
from datetime import datetime
from elasticsearch import Elasticsearch
es = Elasticsearch('https://localhost:9200')
doc = {
'author': 'author_name',
'text': 'Interensting content...',
'timestamp': datetime.now(),
}
resp = es.index(index="test-index", id=1, document=doc)
print(resp['result'])