tool for reindexing elasticsearch db (#5643)

Signed-off-by: Vyacheslav Tumanov <me@slavatumanov.me>
This commit is contained in:
Vyacheslav Tumanov
2024-05-24 00:16:57 +07:00
committed by GitHub
parent 8b0d099b1a
commit ce6ce23444
2 changed files with 33 additions and 2 deletions
+24 -1
View File
@@ -22,7 +22,8 @@ import core, {
type Tx,
type WorkspaceId,
type Ref,
type Doc
type Doc,
DOMAIN_DOC_INDEX_STATE
} from '@hcengineering/core'
import { getWorkspaceDB } from '@hcengineering/mongo'
import { MongoClient } from 'mongodb'
@@ -97,3 +98,25 @@ export async function updateField (
await connection.close()
}
}
export async function recreateElastic (
mongoUrl: string,
workspaceId: WorkspaceId,
transactorUrl: string
): Promise<void> {
const client = new MongoClient(mongoUrl)
const connection = (await connect(transactorUrl, workspaceId, undefined, {
mode: 'backup'
})) as unknown as CoreClient & BackupClient
try {
await client.connect()
const db = getWorkspaceDB(client, workspaceId)
await db
.collection(DOMAIN_DOC_INDEX_STATE)
.updateMany({ _class: core.class.DocIndexState }, { $set: { stages: {} } })
await connection.sendForceClose()
} finally {
await client.close()
await connection.close()
}
}