import csv
import sys
from pathlib import Path

from elasticsearch import Elasticsearch, helpers

if len(sys.argv) < 2:
    print("Usage: python mapping.py <outputs_folder>")
    sys.exit(1)

parsed_dumps = Path(sys.argv[1]) / "parsed_dumps"
csv_files = parsed_dumps.glob("*.csv")

es = Elasticsearch(host="localhost", port=9200)

for csv_file in csv_files:
    with open(parsed_dumps / csv_file.name, "r") as file:
        reader = csv.DictReader(file)
        helpers.bulk(es, reader, index=csv_file.name.split(".")[0])
