Compare commits

...

6 Commits

Author SHA1 Message Date
4d11dca22c 1.0.53 2023-08-17 19:24:35 +02:00
3079adbbd9 fix(core): update 2023-08-17 19:24:34 +02:00
bc9de8e4d6 1.0.52 2023-08-17 19:21:27 +02:00
3fa7d66236 fix(core): update 2023-08-17 19:21:26 +02:00
2a0b0b2478 1.0.51 2023-08-14 13:09:21 +02:00
35e99663a4 fix(core): update 2023-08-14 13:09:20 +02:00
7 changed files with 54 additions and 5 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@apiclient.xyz/elasticsearch", "name": "@apiclient.xyz/elasticsearch",
"version": "1.0.50", "version": "1.0.53",
"private": false, "private": false,
"description": "log to elasticsearch in a kibana compatible format", "description": "log to elasticsearch in a kibana compatible format",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@apiclient.xyz/elasticsearch', name: '@apiclient.xyz/elasticsearch',
version: '1.0.50', version: '1.0.53',
description: 'log to elasticsearch in a kibana compatible format' 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'; import type { ILogContext, ILogPackage, ILogDestination } from '@pushrocks/smartlog-interfaces';
// other classes // other classes
import { ElasticScheduler } from './elasticsearch.classes.elasticscheduler.js'; import { ElasticScheduler } from './els.classes.elasticscheduler.js';
import { ElasticIndex } from './elasticsearch.classes.elasticindex.js'; import { ElasticIndex } from './els.classes.elasticindex.js';
export interface IStandardLogParams { export interface IStandardLogParams {
message: string; message: string;

View File

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