Files
fake-adsb-index/src/index.mjs
joe fleming aca5c03388 chore: change get-data exports
export a function for the specific opensky data, re-org code
2018-11-02 14:56:07 -07:00

26 lines
783 B
JavaScript

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}`);
}