fix(core): update

This commit is contained in:
Philipp Kunz 2023-08-17 19:21:26 +02:00
parent 2a0b0b2478
commit 3fa7d66236
6 changed files with 51 additions and 3 deletions

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@apiclient.xyz/elasticsearch',
version: '1.0.51',
version: '1.0.52',
description: 'log to elasticsearch in a kibana compatible format'
}

View File

@ -0,0 +1,47 @@
import { Client as ElasticClient } from '@elastic/elasticsearch';
export class FastPush {
private client: ElasticClient;
constructor(node: string, auth?: { username: string; password: string }) {
this.client = new ElasticClient({
node: node,
...(auth && { auth: auth }),
});
}
async pushToIndex(indexName: string, docArray: any[]) {
if (docArray.length === 0) return;
// Check if index exists
const { body: indexExists } = await this.client.indices.exists({ index: indexName });
if (!indexExists) {
// Create index with mappings (for simplicity, we use dynamic mapping)
await this.client.indices.create({
index: indexName,
body: {
mappings: {
dynamic: "true",
properties: {
// If there's a need for specific mappings, they can be added here
},
},
},
});
}
// Bulk insert documents
const bulkBody = [];
for (const doc of docArray) {
bulkBody.push({
index: {
_index: indexName,
},
});
bulkBody.push(doc);
}
await this.client.bulk({ body: bulkBody });
}
}

View File

@ -3,8 +3,8 @@ import { Client as ElasticClient } from '@elastic/elasticsearch';
import type { ILogContext, ILogPackage, ILogDestination } from '@pushrocks/smartlog-interfaces';
// other classes
import { ElasticScheduler } from './elasticsearch.classes.elasticscheduler.js';
import { ElasticIndex } from './elasticsearch.classes.elasticindex.js';
import { ElasticScheduler } from './els.classes.elasticscheduler.js';
import { ElasticIndex } from './els.classes.elasticindex.js';
export interface IStandardLogParams {
message: string;

View File

@ -1,3 +1,4 @@
export * from './els.classes.smartlogdestination.js';
export * from './els.classes.fastpush.js';
export * from './els.classes.elasticdoc.js';
export * from './els.classes.kvstore.js';