import elasticsearch from 'elasticsearch'; import logger from './lib/logger.mjs'; import { createIndex, bulkInsert } from './lib/data-source.mjs'; import { getOpenskyData } from './lib/get-data.mjs'; export default async function(indexName, opts = {}) { const client = new elasticsearch.Client({ host: opts.elasticsearch.host, log: opts.elasticsearch.log, httpAuth: opts.elasticsearch.auth, }); // make sure we can connect to the node await client.ping(); // create the target index const index = await createIndex(client, indexName); const records = await getOpenskyData(); logger.debug(`Record count:, ${records.length}`); await bulkInsert(client, index, records); logger.debug(`Successfully indexed ${records.length} records to ${index}`); }