📅  最后修改于: 2022-03-11 14:45:14.918000             🧑  作者: Mango
>>> from datetime import datetime
>>> from elasticsearch import Elasticsearch
# by default we connect to localhost:9200
>>> es = Elasticsearch()
# datetimes will be serialized
>>> es.index(index="my-index-000001", doc_type="test-type", id=42, body={"any": "data", "timestamp": datetime.now()})
{u'_id': u'42', u'_index': u'my-index-000001', u'_type': u'test-type', u'_version': 1, u'ok': True}
# but not deserialized
>>> es.get(index="my-index-000001", doc_type="test-type", id=42)['_source']
{u'any': u'data', u'timestamp': u'2013-05-12T19:45:31.804229'}