Skip to content

Commit

Permalink
feat(reindex): add meta to synchronized index
Browse files Browse the repository at this point in the history
  • Loading branch information
Mati365 committed Oct 22, 2023
1 parent f325f8e commit 60c259b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/reindex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@
],
"dependencies": {
"@elastic/elasticsearch": "^8.10.0",
"@searchpunch/core": "*",
"@searchpunch/logger": "*",
"elastic-builder": "^2.22.0",
"fp-ts": "^2.16.1",
"@searchpunch/core": "*",
"@searchpunch/logger": "*"
"object-hash": "^3.0.0"
},
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@types/object-hash": "^3.0.5"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import hash from 'object-hash';

const MAGIC_ES_SCHEMA_TAG = '@searchpunch/synchronized';

type EsIndexMagicMeta = {
tag: string;
schemaVersion: string;
};

const createIndexMagicMeta = (schema: object): EsIndexMagicMeta => ({
tag: MAGIC_ES_SCHEMA_TAG,
schemaVersion: hash(schema),
});

export const createIndexSchemaWithMagicMeta = <S extends { mappings?: object }>(
schema: S,
) => ({
...schema,
mappings: {
_meta: createIndexMagicMeta(schema),
...schema.mappings,
},
});
1 change: 1 addition & 0 deletions packages/reindex/src/+internal/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './create-index-name-with-timestamp';
export * from './create-index-schema-with-magic-meta';
3 changes: 2 additions & 1 deletion packages/reindex/src/es-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type * as es from '@elastic/elasticsearch';
import { PinoLogger, type AbstractLogger } from '@searchpunch/logger';
import {
createIndexNameWithTimestamp,
createIndexSchemaWithMagicMeta,
type EsMonadicClient,
} from './+internal';

Expand Down Expand Up @@ -93,7 +94,7 @@ export class EsIndex extends ValueObject<EsIndexProps> {

private readonly createTmpIndex = () =>
this.client.index.create({
...this.schema,
...createIndexSchemaWithMagicMeta(this.schema),
index: createIndexNameWithTimestamp(this.indexName),
});
}
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,11 @@
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.3.tgz#291c243e4b94dbfbc0c0ee26b7666f1d5c030e2c"
integrity sha512-ehPtgRgaULsFG8x0NeYJvmyH1hmlfsNLujHe9dQEia/7MAJYdzMSi19JtchUHjmBA6XC/75dK55mzZH+RyieSg==

"@types/object-hash@^3.0.5":
version "3.0.5"
resolved "https://registry.yarnpkg.com/@types/object-hash/-/object-hash-3.0.5.tgz#f028398f9d918a4dcb57c50d16fc15023db6b244"
integrity sha512-WFGeSazfL5BWbEh5ACaAIs5RT6sbVIwBs1rgHUp+kZzX/gub41LEEYWTWbYnE/sKb7hDdPEsGa1Vmcaay2fS5g==

"@types/[email protected]":
version "1.20.2"
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.20.2.tgz#97d26e00cd4a0423b4af620abecf3e6f442b7975"
Expand Down Expand Up @@ -4282,6 +4287,11 @@ npm-run-path@^5.1.0:
dependencies:
path-key "^4.0.0"

object-hash@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/object-hash/-/object-hash-3.0.0.tgz#73f97f753e7baffc0e2cc9d6e079079744ac82e9"
integrity sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==

object-inspect@^1.13.1, object-inspect@^1.9.0:
version "1.13.1"
resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.13.1.tgz#b96c6109324ccfef6b12216a956ca4dc2ff94bc2"
Expand Down

0 comments on commit 60c259b

Please sign in to comment.