Files
fake-adsb-index/src/index.mjs

25 lines
803 B
JavaScript

import elasticsearch from 'elasticsearch';
import logger from './lib/logger.mjs';
import { createIndex, bulkInsert } from './lib/data-source.mjs';
import { getAdbsExchangeData } 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 getAdbsExchangeData(opts.filter);
logger.debug(`Record count:, ${records.length}`);
await bulkInsert(client, index, records);
logger.debug(`Successfully indexed ${records.length} records to ${index}`);
}