You could utilize the bulk
method of the official python package:
import json
from noaa_sdk import noaa
from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk
noaa_client = noaa.NOAA()
alerts = noaa_client.alerts()['features']
es = Elasticsearch()
def save_alerts():
with open('nhc_alerts.json', 'w') as f:
f.write(json.dumps(alerts))
def bulk_sync():
actions = [
{
"_index": "my_noaa_index",
"_source": alert
} for alert in alerts
]
bulk(es, actions)
save_alerts()
bulk_sync()