fix(core): update
This commit is contained in:
parent
fc87fd7ab7
commit
d6a291d8d4
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@apiclient.xyz/elasticsearch',
|
name: '@apiclient.xyz/elasticsearch',
|
||||||
version: '2.0.7',
|
version: '2.0.8',
|
||||||
description: 'log to elasticsearch in a kibana compatible format'
|
description: 'log to elasticsearch in a kibana compatible format'
|
||||||
}
|
}
|
||||||
|
@ -71,9 +71,8 @@ export class ElasticDoc {
|
|||||||
async startPipingSession(options: { onlyNew?: boolean }) {
|
async startPipingSession(options: { onlyNew?: boolean }) {
|
||||||
this.sessionDocs.clear();
|
this.sessionDocs.clear();
|
||||||
this.onlyNew = options.onlyNew;
|
this.onlyNew = options.onlyNew;
|
||||||
|
const indexExists = await this.client.indices.exists({ index: this.index });
|
||||||
if (this.onlyNew) {
|
if (this.onlyNew && indexExists) {
|
||||||
try {
|
|
||||||
const response = await this.client.search({
|
const response = await this.client.search({
|
||||||
index: this.index,
|
index: this.index,
|
||||||
sort: '@timestamp:desc',
|
sort: '@timestamp:desc',
|
||||||
@ -89,16 +88,8 @@ export class ElasticDoc {
|
|||||||
} else {
|
} else {
|
||||||
console.log(`Working in "onlyNew" mode, but no documents found in index ${this.index}. Hence processing all documents now.`);
|
console.log(`Working in "onlyNew" mode, but no documents found in index ${this.index}. Hence processing all documents now.`);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} else if (this.onlyNew && !indexExists) {
|
||||||
// If the search query failed, the index likely doesn't exist or some other error occurred.
|
console.log(`Working in "onlyNew" mode, but index ${this.index} does not exist. Hence processing all documents now.`);
|
||||||
if (e.meta && e.meta.statusCode === 404) {
|
|
||||||
console.log(`Index ${this.index} does not exist. Working in "onlyNew" mode, but will process all documents as the index is empty.`);
|
|
||||||
} else {
|
|
||||||
console.log(`An error occurred while trying to retrieve the latest timestamp: ${e}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.latestTimestamp = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,7 +204,6 @@ export class ElasticDoc {
|
|||||||
|
|
||||||
if (response.hits.hits.length > 0) {
|
if (response.hits.hits.length > 0) {
|
||||||
const hit = response.hits.hits[0];
|
const hit = response.hits.hits[0];
|
||||||
console.log(hit);
|
|
||||||
return {
|
return {
|
||||||
date: hit._source['date'],
|
date: hit._source['date'],
|
||||||
aggregationData: hit._source['aggregationData'],
|
aggregationData: hit._source['aggregationData'],
|
||||||
|
@ -18,7 +18,7 @@ export class FastPush {
|
|||||||
async pushToIndex(indexName: string, docArray: any[], options?: FastPushOptions) {
|
async pushToIndex(indexName: string, docArray: any[], options?: FastPushOptions) {
|
||||||
if (docArray.length === 0) return;
|
if (docArray.length === 0) return;
|
||||||
|
|
||||||
const { body: indexExists } = await this.client.indices.exists({ index: indexName });
|
const indexExists = await this.client.indices.exists({ index: indexName });
|
||||||
|
|
||||||
if (indexExists) {
|
if (indexExists) {
|
||||||
if (options?.deleteIndex) {
|
if (options?.deleteIndex) {
|
||||||
|
@ -27,7 +27,7 @@ export class ElasticKVStore {
|
|||||||
|
|
||||||
private async setupIndex() {
|
private async setupIndex() {
|
||||||
try {
|
try {
|
||||||
const { body: indexExists } = await this.client.indices.exists({ index: this.index });
|
const indexExists = await this.client.indices.exists({ index: this.index });
|
||||||
|
|
||||||
if (!indexExists) {
|
if (!indexExists) {
|
||||||
await this.client.indices.create({
|
await this.client.indices.create({
|
||||||
@ -72,7 +72,7 @@ export class ElasticKVStore {
|
|||||||
index: this.index,
|
index: this.index,
|
||||||
id: key
|
id: key
|
||||||
});
|
});
|
||||||
return response.body._source.value;
|
return response._source['value'];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.meta && error.meta.statusCode === 404) {
|
if (error.meta && error.meta.statusCode === 404) {
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user