mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-23 11:31:57 +03:00
UBERF-6600 Fix index name configuration (#5393)
Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
parent
808b5c8f7d
commit
0bb1e60203
@ -107,4 +107,4 @@ export const fieldStateId = 'fld-v13b'
|
|||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export const fullTextPushStageId = 'fts-v13'
|
export const fullTextPushStageId = 'fts-v14'
|
||||||
|
@ -41,11 +41,16 @@ import { getMetadata } from '@hcengineering/platform'
|
|||||||
import { Domain } from 'node:domain'
|
import { Domain } from 'node:domain'
|
||||||
|
|
||||||
const DEFAULT_LIMIT = 200
|
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 {
|
class ElasticAdapter implements FullTextAdapter {
|
||||||
constructor (
|
constructor (
|
||||||
private readonly client: Client,
|
private readonly client: Client,
|
||||||
private readonly workspaceId: WorkspaceId,
|
private readonly workspaceId: WorkspaceId,
|
||||||
|
private readonly indexName: string,
|
||||||
private readonly _metrics: MeasureContext
|
private readonly _metrics: MeasureContext
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@ -55,6 +60,7 @@ class ElasticAdapter implements FullTextAdapter {
|
|||||||
// const current = await this.client.indices.getMapping({})
|
// const current = await this.client.indices.getMapping({})
|
||||||
// console.log('Mappings', current)
|
// console.log('Mappings', current)
|
||||||
// const mappings = current.body[toWorkspaceString(this.workspaceId)]
|
// const mappings = current.body[toWorkspaceString(this.workspaceId)]
|
||||||
|
const indexName = this.indexName
|
||||||
const result: Record<string, number> = {}
|
const result: Record<string, number> = {}
|
||||||
try {
|
try {
|
||||||
const existsOldIndex = await this.client.indices.exists({
|
const existsOldIndex = await this.client.indices.exists({
|
||||||
@ -260,7 +266,7 @@ class ElasticAdapter implements FullTextAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result = await this.client.search({
|
const result = await this.client.search({
|
||||||
index: indexName,
|
index: this.indexName,
|
||||||
body: elasticQuery
|
body: elasticQuery
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -344,7 +350,7 @@ class ElasticAdapter implements FullTextAdapter {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await this.client.search({
|
const result = await this.client.search({
|
||||||
index: indexName,
|
index: this.indexName,
|
||||||
body: {
|
body: {
|
||||||
query: request,
|
query: request,
|
||||||
size: size ?? 200,
|
size: size ?? 200,
|
||||||
@ -422,7 +428,7 @@ class ElasticAdapter implements FullTextAdapter {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await this.client.search({
|
const result = await this.client.search({
|
||||||
index: indexName,
|
index: this.indexName,
|
||||||
body: {
|
body: {
|
||||||
query: request,
|
query: request,
|
||||||
size: options?.size ?? 200,
|
size: options?.size ?? 200,
|
||||||
@ -449,14 +455,14 @@ class ElasticAdapter implements FullTextAdapter {
|
|||||||
}
|
}
|
||||||
if (doc.data === undefined) {
|
if (doc.data === undefined) {
|
||||||
await this.client.index({
|
await this.client.index({
|
||||||
index: indexName,
|
index: this.indexName,
|
||||||
id: doc.id,
|
id: doc.id,
|
||||||
type: '_doc',
|
type: '_doc',
|
||||||
body: wsDoc
|
body: wsDoc
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
await this.client.index({
|
await this.client.index({
|
||||||
index: indexName,
|
index: this.indexName,
|
||||||
id: doc.id,
|
id: doc.id,
|
||||||
type: '_doc',
|
type: '_doc',
|
||||||
pipeline: 'attachment',
|
pipeline: 'attachment',
|
||||||
@ -468,7 +474,7 @@ class ElasticAdapter implements FullTextAdapter {
|
|||||||
|
|
||||||
async update (id: Ref<Doc>, update: Record<string, any>): Promise<TxResult> {
|
async update (id: Ref<Doc>, update: Record<string, any>): Promise<TxResult> {
|
||||||
await this.client.update({
|
await this.client.update({
|
||||||
index: indexName,
|
index: this.indexName,
|
||||||
id,
|
id,
|
||||||
body: {
|
body: {
|
||||||
doc: update
|
doc: update
|
||||||
@ -485,7 +491,7 @@ class ElasticAdapter implements FullTextAdapter {
|
|||||||
|
|
||||||
const operations = part.flatMap((doc) => {
|
const operations = part.flatMap((doc) => {
|
||||||
const wsDoc = { workspaceId: toWorkspaceString(this.workspaceId), ...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 })
|
const response = await this.client.bulk({ refresh: true, body: operations })
|
||||||
@ -513,7 +519,7 @@ class ElasticAdapter implements FullTextAdapter {
|
|||||||
await this.client.deleteByQuery(
|
await this.client.deleteByQuery(
|
||||||
{
|
{
|
||||||
type: '_doc',
|
type: '_doc',
|
||||||
index: indexName,
|
index: this.indexName,
|
||||||
body: {
|
body: {
|
||||||
query: {
|
query: {
|
||||||
bool: {
|
bool: {
|
||||||
@ -548,7 +554,7 @@ class ElasticAdapter implements FullTextAdapter {
|
|||||||
|
|
||||||
async load (docs: Ref<Doc>[]): Promise<IndexedDoc[]> {
|
async load (docs: Ref<Doc>[]): Promise<IndexedDoc[]> {
|
||||||
const resp = await this.client.search({
|
const resp = await this.client.search({
|
||||||
index: indexName,
|
index: this.indexName,
|
||||||
type: '_doc',
|
type: '_doc',
|
||||||
body: {
|
body: {
|
||||||
query: {
|
query: {
|
||||||
@ -586,6 +592,7 @@ export async function createElasticAdapter (
|
|||||||
const client = new Client({
|
const client = new Client({
|
||||||
node: url
|
node: url
|
||||||
})
|
})
|
||||||
|
const indexName = getIndexName()
|
||||||
|
|
||||||
return new ElasticAdapter(client, workspaceId, metrics)
|
return new ElasticAdapter(client, workspaceId, indexName, metrics)
|
||||||
}
|
}
|
||||||
|
@ -39,11 +39,15 @@ import { getMetadata, PlatformError, unknownStatus } from '@hcengineering/platfo
|
|||||||
import serverCore, { DbAdapter, IndexedDoc } from '@hcengineering/server-core'
|
import serverCore, { DbAdapter, IndexedDoc } from '@hcengineering/server-core'
|
||||||
import { createHash } from 'node:crypto'
|
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 {
|
class ElasticDataAdapter implements DbAdapter {
|
||||||
constructor (
|
constructor (
|
||||||
readonly workspaceId: WorkspaceId,
|
readonly workspaceId: WorkspaceId,
|
||||||
readonly client: Client
|
readonly client: Client,
|
||||||
|
readonly indexName: string
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async findAll<T extends Doc>(
|
async findAll<T extends Doc>(
|
||||||
@ -80,7 +84,7 @@ class ElasticDataAdapter implements DbAdapter {
|
|||||||
try {
|
try {
|
||||||
if (!listRecieved) {
|
if (!listRecieved) {
|
||||||
const q = {
|
const q = {
|
||||||
index: indexName,
|
index: this.indexName,
|
||||||
type: '_doc',
|
type: '_doc',
|
||||||
scroll: '23h',
|
scroll: '23h',
|
||||||
// search_type: 'scan', //if I use search_type then it requires size otherwise it shows 0 result
|
// 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) {
|
while (toLoad.length > 0) {
|
||||||
const part = toLoad.splice(0, 5000)
|
const part = toLoad.splice(0, 5000)
|
||||||
const resp = await this.client.search({
|
const resp = await this.client.search({
|
||||||
index: indexName,
|
index: this.indexName,
|
||||||
type: '_doc',
|
type: '_doc',
|
||||||
body: {
|
body: {
|
||||||
query: {
|
query: {
|
||||||
@ -218,7 +222,7 @@ class ElasticDataAdapter implements DbAdapter {
|
|||||||
await this.client.deleteByQuery(
|
await this.client.deleteByQuery(
|
||||||
{
|
{
|
||||||
type: '_doc',
|
type: '_doc',
|
||||||
index: indexName,
|
index: this.indexName,
|
||||||
body: {
|
body: {
|
||||||
query: {
|
query: {
|
||||||
bool: {
|
bool: {
|
||||||
@ -247,7 +251,7 @@ class ElasticDataAdapter implements DbAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const operations = part.flatMap((doc) => [
|
const operations = part.flatMap((doc) => [
|
||||||
{ index: { _index: indexName, _id: doc._id } },
|
{ index: { _index: this.indexName, _id: doc._id } },
|
||||||
{
|
{
|
||||||
workspaceId: toWorkspaceString(this.workspaceId),
|
workspaceId: toWorkspaceString(this.workspaceId),
|
||||||
...(doc as FullTextData).data
|
...(doc as FullTextData).data
|
||||||
@ -268,7 +272,7 @@ class ElasticDataAdapter implements DbAdapter {
|
|||||||
await this.client.deleteByQuery(
|
await this.client.deleteByQuery(
|
||||||
{
|
{
|
||||||
type: '_doc',
|
type: '_doc',
|
||||||
index: indexName,
|
index: this.indexName,
|
||||||
body: {
|
body: {
|
||||||
query: {
|
query: {
|
||||||
bool: {
|
bool: {
|
||||||
@ -308,5 +312,6 @@ export async function createElasticBackupDataAdapter (
|
|||||||
const client = new Client({
|
const client = new Client({
|
||||||
node: url
|
node: url
|
||||||
})
|
})
|
||||||
return new ElasticDataAdapter(workspaceId, client)
|
const indexName = getIndexName()
|
||||||
|
return new ElasticDataAdapter(workspaceId, client, indexName)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user