-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade Elasticsearch from 7.17 to 8 #7389
Changes from all commits
78ce487
e75647f
f21d7d5
a83860f
14b6738
6caf8b5
932ecb6
406e746
5600f93
5bf1d00
0925e07
49b0707
f9cdd6f
82a672b
6645e83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved from search |
||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* OpenCRVS is also distributed under the terms of the Civil Registration | ||
* & Healthcare Disclaimer located at http://opencrvs.org/license. | ||
* | ||
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. | ||
*/ | ||
|
||
export const enum EVENT { | ||
BIRTH = 'Birth', | ||
DEATH = 'Death', | ||
MARRIAGE = 'Marriage' | ||
} | ||
|
||
export const IN_PROGRESS_STATUS = 'IN_PROGRESS' | ||
export const ARCHIVED_STATUS = 'ARCHIVED' | ||
export const DECLARED_STATUS = 'DECLARED' | ||
export const REJECTED_STATUS = 'REJECTED' | ||
export const VALIDATED_STATUS = 'VALIDATED' | ||
const WAITING_VALIDATION_STATUS = 'WAITING_VALIDATION' | ||
export const REGISTERED_STATUS = 'REGISTERED' | ||
const REINSTATED_STATUS = 'REINSTATED' | ||
export const CERTIFIED_STATUS = 'CERTIFIED' | ||
export const ISSUED_STATUS = 'ISSUED' | ||
const REQUESTED_CORRECTION_STATUS = 'REQUESTED_CORRECTION' | ||
const DECLARATION_UPDATED_STATUS = 'DECLARATION_UPDATED' | ||
|
||
export const validStatusMapping = { | ||
[ARCHIVED_STATUS]: [ | ||
DECLARED_STATUS, | ||
REJECTED_STATUS, | ||
VALIDATED_STATUS | ||
] as const, | ||
[IN_PROGRESS_STATUS]: [null] as const, | ||
[DECLARED_STATUS]: [ARCHIVED_STATUS, null] as const, | ||
[REJECTED_STATUS]: [ | ||
DECLARED_STATUS, | ||
IN_PROGRESS_STATUS, | ||
WAITING_VALIDATION_STATUS, | ||
VALIDATED_STATUS, | ||
ARCHIVED_STATUS | ||
] as const, | ||
[VALIDATED_STATUS]: [ | ||
DECLARED_STATUS, | ||
IN_PROGRESS_STATUS, | ||
REJECTED_STATUS, | ||
ARCHIVED_STATUS, | ||
DECLARATION_UPDATED_STATUS, | ||
null | ||
] as const, | ||
[WAITING_VALIDATION_STATUS]: [ | ||
null, | ||
DECLARED_STATUS, | ||
IN_PROGRESS_STATUS, | ||
REJECTED_STATUS, | ||
VALIDATED_STATUS, | ||
DECLARATION_UPDATED_STATUS | ||
] as const, | ||
[REGISTERED_STATUS]: [ | ||
null, | ||
DECLARED_STATUS, | ||
IN_PROGRESS_STATUS, | ||
REJECTED_STATUS, | ||
VALIDATED_STATUS, | ||
WAITING_VALIDATION_STATUS | ||
] as const, | ||
[CERTIFIED_STATUS]: [REGISTERED_STATUS, ISSUED_STATUS] as const, | ||
[ISSUED_STATUS]: [CERTIFIED_STATUS] as const, | ||
[REQUESTED_CORRECTION_STATUS]: [REGISTERED_STATUS, CERTIFIED_STATUS] as const, | ||
[REINSTATED_STATUS]: [ARCHIVED_STATUS] as const | ||
} | ||
|
||
export interface ICorrection { | ||
section: string | ||
fieldName: string | ||
oldValue: string | ||
newValue: string | number | boolean | ||
} | ||
|
||
export interface IAssignment { | ||
practitionerId: string | ||
firstName: string | ||
lastName: string | ||
officeName: string | ||
} | ||
|
||
export interface IOperationHistory { | ||
operationType: keyof typeof validStatusMapping | ||
operatedOn: string | ||
} | ||
|
||
export interface SearchDocument { | ||
compositionId: string | ||
compositionType?: string | ||
event?: EVENT | ||
type?: string | ||
informantType?: string | ||
contactNumber?: string | ||
contactEmail?: string | ||
dateOfDeclaration?: string | ||
trackingId?: string | ||
registrationNumber?: string | ||
eventLocationId?: string | ||
eventJurisdictionIds?: string[] | ||
eventCountry?: string | ||
declarationLocationId?: string | ||
declarationJurisdictionIds?: string[] | ||
rejectReason?: string | ||
rejectComment?: string | ||
relatesTo?: string[] | ||
childFirstNames?: string | ||
childFamilyName?: string | ||
childFirstNamesLocal?: string | ||
motherFirstNames?: string | ||
motherFamilyName?: string | ||
motherDoB?: string | ||
motherIdentifier?: string | ||
childDoB?: string | ||
childIdentifier?: string | ||
createdBy?: string | ||
updatedBy?: string | ||
createdAt?: string | ||
modifiedAt?: string | ||
assignment?: IAssignment | null | ||
operationHistories?: IOperationHistory[] | ||
} | ||
|
||
/** | ||
* Takes up elastic search total and returns the number of documents independent of 'rest_total_hits_as_int' setting | ||
* https://github.com/elastic/elasticsearch-js/issues/1604 | ||
* @param total total number of documents | ||
*/ | ||
export const getSearchTotalCount = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only new construct for the moved file |
||
total: number | { value: number } | undefined | ||
) => { | ||
if (typeof total === 'number') { | ||
return total | ||
} | ||
return total?.value || 0 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,11 @@ | |
"gen:schema:watch": "nodemon --quiet --on-change-only -e graphql -i src/graphql/schema.graphql -x 'yarn gen:schema'", | ||
"gen:types:watch": "nodemon --quiet --on-change-only -w src/graphql/schema.graphql -x 'yarn gen:types'", | ||
"open:cov": "yarn test && opener coverage/index.html", | ||
"lint": "eslint -c .eslintrc.js --fix ./src --max-warnings=0", | ||
"lint": "eslint -c .eslintrc.js --fix ./src", | ||
"precommit": "lint-staged" | ||
}, | ||
"dependencies": { | ||
"@elastic/elasticsearch": "7.17.13", | ||
"@elastic/elasticsearch": "8.13.1", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. elasticsearch.js does not need to follow the same minor as docker image. |
||
"@graphql-tools/graphql-file-loader": "^7.5.16", | ||
"@graphql-tools/load": "^7.8.13", | ||
"@graphql-tools/schema": "^9.0.17", | ||
|
@@ -82,6 +82,7 @@ | |
"@types/jwt-decode": "^2.2.1", | ||
"@types/lodash": "^4.14.108", | ||
"@types/node-fetch": "^2.5.12", | ||
"@types/node": "18.11.18", | ||
"@types/redis": "^2.8.6", | ||
"@types/uuid": "^3.4.3", | ||
"@typescript-eslint/eslint-plugin": "^4.5.0", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,8 @@ import { Db, MongoClient } from 'mongodb' | |
import { | ||
updateComposition, | ||
searchCompositionByCriteria | ||
// eslint-disable-next-line import/no-relative-parent-imports | ||
} from '../../utils/elasticsearch-helper.js' | ||
import { getSearchTotalCount } from '@opencrvs/commons' | ||
|
||
// THIS MIGRATION POPULATES THE MISSING EVENTLOCATIONIDS OR EVENTJURISDICTIONS IDS DUE TO THE ISSUE - #5242 | ||
|
||
|
@@ -56,8 +56,9 @@ export const up = async (db: Db, client: MongoClient) => { | |
|
||
const compositionsWithoutLocationIdsResult = | ||
await searchCompositionByCriteria(searchCriteria) | ||
const totalCompositionsWithoutLocationIds = | ||
compositionsWithoutLocationIdsResult?.body.hits.total.value || 0 | ||
const totalCompositionsWithoutLocationIds = getSearchTotalCount( | ||
compositionsWithoutLocationIdsResult?.body?.hits.total | ||
) | ||
|
||
while (processedDocCount < totalCompositionsWithoutLocationIds) { | ||
const elasticDocBatchResult = await searchCompositionByCriteria( | ||
|
@@ -79,7 +80,7 @@ export const up = async (db: Db, client: MongoClient) => { | |
} catch (error: any) { | ||
// eslint-disable-next-line no-console | ||
console.error( | ||
`Migration - ElasticSearch :: Process for populating missing eventLocationId/eventJurisdictionIds for ${elasticDoc.id} failed : ${error.stack}` | ||
`Migration - ElasticSearch :: Process for populating missing eventLocationId/eventJurisdictionIds for ${elasticDoc._id} failed: ${error.stack}` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type error here. On the function below, |
||
) | ||
} | ||
} | ||
|
@@ -90,7 +91,7 @@ export const up = async (db: Db, client: MongoClient) => { | |
await session.endSession() | ||
// eslint-disable-next-line no-console | ||
console.log( | ||
`Migration - ElasticSearch :: Process for populating missing eventLocationId/eventJurisdictionIds completed successfully.` | ||
`Migration - ElasticSearch :: Process for populating missing eventLocationId/eventJurisdictionIds completed successfully.` | ||
) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might just be the reason why the reindexing wasn't working properly on our servers!