Upload data to ES Index, using Python
Apr 20, 2021
import json
import os from elasticsearch import Elasticsearches = Elasticsearch('https://your-url.com')
es_index_name = os.getenv('ES_INDEX_NAME', 'index-name')
if __name__ == '__main__':
with open('jsonFilePath.json') as f:
data = json.load(f)
for d in data:
print(d)
es.index(es_index_name, body=d)
Upload data to ES Index after typecasting into an object:
import json# import os from elasticsearch import Elasticsearch# es = Elasticsearch('https://url.com')# es_index_name = os.getenv('ES_INDEX_NAME', 'index-name')if __name__ == '__main__':with open('sample-json.json') as f:data = json.load(f)for d in data:print('\n')if(d.get("heatmap")):x = {"heatmap": d.get("heatmap"),"dwell-time": d.get("dwell-time"),"cameraSlug": d.get("cameraId"),"storeSlug": d.get("store"),"timeStamp": d.get("timeStamp"),"solutionSlug": d.get("solutionSlug"),"objectName": d.get("objectName")}print("data" , x)print('\n')# es.index(es_index_name, body=d)