diff --git a/server/core/src/indexer/types.ts b/server/core/src/indexer/types.ts index 0c0a03d005..16e2a993af 100644 --- a/server/core/src/indexer/types.ts +++ b/server/core/src/indexer/types.ts @@ -107,4 +107,4 @@ export const fieldStateId = 'fld-v13b' /** * @public */ -export const fullTextPushStageId = 'fts-v13' +export const fullTextPushStageId = 'fts-v14' diff --git a/server/elastic/src/adapter.ts b/server/elastic/src/adapter.ts index 4f38c64ec5..663e1279e7 100644 --- a/server/elastic/src/adapter.ts +++ b/server/elastic/src/adapter.ts @@ -41,11 +41,16 @@ import { getMetadata } from '@hcengineering/platform' import { Domain } from 'node:domain' const DEFAULT_LIMIT = 200 -const indexName = getMetadata(serverCore.metadata.ElasticIndexName) ?? 'storage_index' + +function getIndexName (): string { + return getMetadata(serverCore.metadata.ElasticIndexName) ?? 'storage_index' +} + class ElasticAdapter implements FullTextAdapter { constructor ( private readonly client: Client, private readonly workspaceId: WorkspaceId, + private readonly indexName: string, private readonly _metrics: MeasureContext ) {} @@ -55,6 +60,7 @@ class ElasticAdapter implements FullTextAdapter { // const current = await this.client.indices.getMapping({}) // console.log('Mappings', current) // const mappings = current.body[toWorkspaceString(this.workspaceId)] + const indexName = this.indexName const result: Record = {} try { const existsOldIndex = await this.client.indices.exists({ @@ -260,7 +266,7 @@ class ElasticAdapter implements FullTextAdapter { } const result = await this.client.search({ - index: indexName, + index: this.indexName, body: elasticQuery }) @@ -344,7 +350,7 @@ class ElasticAdapter implements FullTextAdapter { try { const result = await this.client.search({ - index: indexName, + index: this.indexName, body: { query: request, size: size ?? 200, @@ -422,7 +428,7 @@ class ElasticAdapter implements FullTextAdapter { try { const result = await this.client.search({ - index: indexName, + index: this.indexName, body: { query: request, size: options?.size ?? 200, @@ -449,14 +455,14 @@ class ElasticAdapter implements FullTextAdapter { } if (doc.data === undefined) { await this.client.index({ - index: indexName, + index: this.indexName, id: doc.id, type: '_doc', body: wsDoc }) } else { await this.client.index({ - index: indexName, + index: this.indexName, id: doc.id, type: '_doc', pipeline: 'attachment', @@ -468,7 +474,7 @@ class ElasticAdapter implements FullTextAdapter { async update (id: Ref, update: Record): Promise { await this.client.update({ - index: indexName, + index: this.indexName, id, body: { doc: update @@ -485,7 +491,7 @@ class ElasticAdapter implements FullTextAdapter { const operations = part.flatMap((doc) => { const wsDoc = { workspaceId: toWorkspaceString(this.workspaceId), ...doc } - return [{ index: { _index: indexName, _id: doc.id } }, { ...wsDoc, type: '_doc' }] + return [{ index: { _index: this.indexName, _id: doc.id } }, { ...wsDoc, type: '_doc' }] }) const response = await this.client.bulk({ refresh: true, body: operations }) @@ -513,7 +519,7 @@ class ElasticAdapter implements FullTextAdapter { await this.client.deleteByQuery( { type: '_doc', - index: indexName, + index: this.indexName, body: { query: { bool: { @@ -548,7 +554,7 @@ class ElasticAdapter implements FullTextAdapter { async load (docs: Ref[]): Promise { const resp = await this.client.search({ - index: indexName, + index: this.indexName, type: '_doc', body: { query: { @@ -586,6 +592,7 @@ export async function createElasticAdapter ( const client = new Client({ node: url }) + const indexName = getIndexName() - return new ElasticAdapter(client, workspaceId, metrics) + return new ElasticAdapter(client, workspaceId, indexName, metrics) } diff --git a/server/elastic/src/backup.ts b/server/elastic/src/backup.ts index 52e92e38b9..eb8dcb249e 100644 --- a/server/elastic/src/backup.ts +++ b/server/elastic/src/backup.ts @@ -39,11 +39,15 @@ import { getMetadata, PlatformError, unknownStatus } from '@hcengineering/platfo import serverCore, { DbAdapter, IndexedDoc } from '@hcengineering/server-core' import { createHash } from 'node:crypto' -const indexName = getMetadata(serverCore.metadata.ElasticIndexName) ?? 'storage_index' +function getIndexName (): string { + return getMetadata(serverCore.metadata.ElasticIndexName) ?? 'storage_index' +} + class ElasticDataAdapter implements DbAdapter { constructor ( readonly workspaceId: WorkspaceId, - readonly client: Client + readonly client: Client, + readonly indexName: string ) {} async findAll( @@ -80,7 +84,7 @@ class ElasticDataAdapter implements DbAdapter { try { if (!listRecieved) { const q = { - index: indexName, + index: this.indexName, type: '_doc', scroll: '23h', // search_type: 'scan', //if I use search_type then it requires size otherwise it shows 0 result @@ -171,7 +175,7 @@ class ElasticDataAdapter implements DbAdapter { while (toLoad.length > 0) { const part = toLoad.splice(0, 5000) const resp = await this.client.search({ - index: indexName, + index: this.indexName, type: '_doc', body: { query: { @@ -218,7 +222,7 @@ class ElasticDataAdapter implements DbAdapter { await this.client.deleteByQuery( { type: '_doc', - index: indexName, + index: this.indexName, body: { query: { bool: { @@ -247,7 +251,7 @@ class ElasticDataAdapter implements DbAdapter { } const operations = part.flatMap((doc) => [ - { index: { _index: indexName, _id: doc._id } }, + { index: { _index: this.indexName, _id: doc._id } }, { workspaceId: toWorkspaceString(this.workspaceId), ...(doc as FullTextData).data @@ -268,7 +272,7 @@ class ElasticDataAdapter implements DbAdapter { await this.client.deleteByQuery( { type: '_doc', - index: indexName, + index: this.indexName, body: { query: { bool: { @@ -308,5 +312,6 @@ export async function createElasticBackupDataAdapter ( const client = new Client({ node: url }) - return new ElasticDataAdapter(workspaceId, client) + const indexName = getIndexName() + return new ElasticDataAdapter(workspaceId, client, indexName) }