fix: error thrown on consecutive connector executions

Fixes #73
This commit is contained in:
Jovan Krunić
2020-11-10 15:38:42 +01:00
committed by Rainer Killinger
parent 18359fdab3
commit 2259da317a
3 changed files with 28 additions and 15 deletions

View File

@@ -485,14 +485,15 @@ export class Elasticsearch implements Database {
const item = await this.getObject(object.uid);
// we have to check that the item will get replaced if the index is rolled over
// check that the item will get replaced if the index is rolled over (index with the same name excluding ending uid)
if (typeof item !== 'undefined') {
const indexOfNew = Elasticsearch.getIndex(obj.type, bulk.source, bulk);
const oldIndex = item._index;
// new item doesn't replace the old one
if (oldIndex.substring(0, oldIndex.length - Elasticsearch.INDEX_UID_LENGTH + 1)
!== indexOfNew.substring(0, indexOfNew.length - Elasticsearch.INDEX_UID_LENGTH + 1)) {
// tslint:disable-next-line:no-magic-numbers
if (oldIndex.substring(0, oldIndex.lastIndexOf('_'))
!== indexOfNew.substring(0, indexOfNew.lastIndexOf('_'))) {
throw new Error(
// tslint:disable-next-line: no-magic-numbers
`Object "${obj.uid}" already exists. Object was: ${JSON.stringify(obj, null, 2)}`,