fix(core): update

This commit is contained in:
Philipp Kunz 2023-08-29 09:31:42 +02:00
parent a1b5bf5c0c
commit 93f739c79e
2 changed files with 13 additions and 12 deletions

View File

@ -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'
}

View File

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