Skip to content
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

Merged
merged 15 commits into from
Jul 30, 2024
Merged

Conversation

makelicious
Copy link
Collaborator

@makelicious makelicious commented Jul 17, 2024

In order to fix the issue #7149 we needed to upgrade to next major version of elasticsearch.

Changes:

  1. Add {meta: true} option to keep the payload compatible with 7.x.x format
  2. Fix type issues revealed by the upgrade
  3. Add search.ts to share type related items between services (migration & search)

Needs config changes from: opencrvs/opencrvs-countryconfig#216

@@ -0,0 +1,143 @@
/*
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from search

* https://github.com/elastic/elasticsearch-js/issues/1604
* @param total total number of documents
*/
export const getSearchTotalCount = (
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only new construct for the moved file

@@ -21,7 +21,7 @@
"precommit": "lint-staged"
},
"dependencies": {
"@elastic/elasticsearch": "7.17.13",
"@elastic/elasticsearch": "8.13.1",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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. 8.14.x had some issues with undici.

@@ -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}`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type error here. On the function below, _id is used, too.

return await client.update(
{
index: ELASTICSEARCH_INDEX_NAME,
// type: 'compositions', @todo: check whether this should work
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could someone confirm that these are not actually needed? type was deprecated and is only used here

Related to breaking change.
https://github.com/elastic/elasticsearch/pull/53670/files#diff-f5af866d898d3af4dd418c4212ad2d3ebb89e941d8ad4052a7512bf416a7e2d5L84

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types property was removed from the elasticsearch/dbhelper.ts file here: fc2594d#diff-f1ee21482bf25e832b890c7a5d40825103ec072bf33ec84275d4022b12adfd75L26
So it should safe to do so here as well

return await client.search<SearchDocument>(
{
index: ELASTICSEARCH_INDEX_NAME,
// type: 'compositions', @todo: check whether this should work
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"allowJs": true,
"moduleResolution": "node",
"moduleResolution": "node16",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required for commons import

} from '@opencrvs/commons/types'
import { findName } from '@search/features/fhir/fhir-utils'

export const enum EVENT {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved under commons/search

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would appreciate second pair of eyes especially here to ensure this stayed as it should

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a single comment otherwise looked fine to me!

Copy link
Collaborator

@Zangetsu101 Zangetsu101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @makelicious! Really appreciate the small refactors here & there

@@ -252,6 +252,7 @@ services:
- HEARTH_MONGO_URL=mongodb://mongo1/hearth-dev
- DASHBOARD_MONGO_URL=mongodb://mongo1/performance
- OPENHIM_MONGO_URL=mongodb://mongo1/openhim-dev
- SEARCH_URL=http://search:9090/
Copy link
Collaborator

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!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to just remove this migration as we are running the elastic reindex on every deploy from here: https://github.com/opencrvs/opencrvs-core/blob/develop/packages/migration/run-migrations.sh#L42

return await client.update(
{
index: ELASTICSEARCH_INDEX_NAME,
// type: 'compositions', @todo: check whether this should work
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The types property was removed from the elasticsearch/dbhelper.ts file here: fc2594d#diff-f1ee21482bf25e832b890c7a5d40825103ec072bf33ec84275d4022b12adfd75L26
So it should safe to do so here as well

Comment on lines 155 to 158
bool: {
must: {
bool: {
must: [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool: {
must: {
bool: {
must: [
bool: {
must: [

We probably don't the extra nesting right? It wasn't there previously too

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we don't! Glad that you spotted it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a single comment otherwise looked fine to me!

@makelicious makelicious marked this pull request as ready for review July 30, 2024 06:24
@makelicious makelicious merged commit f107c25 into develop Jul 30, 2024
21 of 22 checks passed
@makelicious makelicious deleted the deploy-elastic-8143-image-2 branch July 30, 2024 06:59
@makelicious makelicious restored the deploy-elastic-8143-image-2 branch July 30, 2024 07:00
github-actions bot pushed a commit that referenced this pull request Jul 30, 2024
makelicious added a commit that referenced this pull request Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants