From 93f739c79ecf9615a45bf342c5af61cddcb37ba1 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Tue, 29 Aug 2023 09:31:42 +0200 Subject: [PATCH] fix(core): update --- ts/00_commitinfo_data.ts | 2 +- ts/els.classes.elasticdoc.ts | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 4190546..991cfac 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@apiclient.xyz/elasticsearch', - version: '2.0.2', + version: '2.0.3', description: 'log to elasticsearch in a kibana compatible format' } diff --git a/ts/els.classes.elasticdoc.ts b/ts/els.classes.elasticdoc.ts index 8f87927..fb09520 100644 --- a/ts/els.classes.elasticdoc.ts +++ b/ts/els.classes.elasticdoc.ts @@ -90,12 +90,6 @@ export class ElasticDoc { async pipeDocument(optionsArg: { docId: string; timestamp?: string | number; doc: any }) { // If 'onlyNew' is true, compare the document timestamp with the latest timestamp - if (this.onlyNew) { - if (this.latestTimestamp && optionsArg.timestamp <= this.latestTimestamp) { - // Omit the document - return; - } - } await this.ensureIndexExists(optionsArg.doc); @@ -104,11 +98,18 @@ export class ElasticDoc { ...(optionsArg.timestamp && { '@timestamp': optionsArg.timestamp }), }; - await this.client.index({ - index: this.index, - id: optionsArg.docId, - body: documentBody, - }); + if (this.onlyNew) { + if (this.latestTimestamp && optionsArg.timestamp <= this.latestTimestamp) { + // Omit the document + return; + } else { + await this.client.index({ + index: this.index, + id: optionsArg.docId, + body: documentBody, + }); + } + } this.sessionDocs.add(optionsArg.docId); }