Add Timestamp to ElasticSearch with Elasticsearch-py using Bulk-API

Fixed my own problem. Basically, I needed to add mappings for the timestamp when I created the index.

request_body = {
    "settings" : {
        "number_of_shards": 1,
        "number_of_replicas": 0
    },
    "mappings" : {
        "_default_":{
            "_timestamp":{
                 "enabled":"true",
                 "store":"true",
                 "path":"plugins.time_stamp.string",
                 "format":"yyyy-MM-dd HH:m:ss"
             }
         }
    }
}
print("creating '%s' index..." % (index_name))
res = es.indices.create(index = index_name, body = request_body)
print(" response: '%s'" % (res))

In the latest versions of Elasticsearch, just using the PUT/POST API and ISOFORMAT strings should work.

import datetime
import requests 

query = json.dumps(
{
 "createdAt": datetime.datetime.now().replace(microsecond=0).isoformat(),
}
)
response = requests.post("https://search-XYZ.com/your-index/log", data=query,
               headers={'Content-Type': 'application/json'})
print(response)