TLDR; How can I bulk format my JSON file for ingestion to Elasticsearch?
I am attempting to ingest some NOAA data into Elasticsearch and have been utilizing NOAA Py
How about utilizing the bulk
method of the official python client?
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()