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

Opensearch Migration #259

Merged
merged 14 commits into from
Mar 13, 2025
8 changes: 5 additions & 3 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ jobs:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:11.5
image: postgres:16.3
env:
POSTGRES_MULTIPLE_DATABASES: searchneu_dev
POSTGRES_USER: postgres
ports:
- 5432:5432
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0
image: opensearchproject/opensearch:2.19.0
env:
discovery.type: single-node
- discovery.type=single-node
- plugins.security.disabled=true
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=sUpp3rS3curePa55W0RD!
ports:
- 9200:9200
env:
Expand Down
9 changes: 6 additions & 3 deletions infrastructure/dev/compose.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
postgresql:
image: postgres:11.19-bullseye
image: postgres:16.3
ports:
- 5432:5432
volumes:
Expand All @@ -11,11 +11,14 @@ services:
- POSTGRES_USER=postgres
env_file:
- ../../.env
es:
image: docker.elastic.co/elasticsearch/elasticsearch:7.10.0

opensearch:
image: opensearchproject/opensearch:2.19.0
ports:
- 9200:9200
environment:
- discovery.type=single-node
- plugins.security.disabled=true
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=sUpp3rS3curePa55W0RD!
volumes:
pg:
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"about:babel-node-ts": "//// This command is used to run Typescript files on the fly. Mainly used in other commands, not standalone",
"babel-node-ts": "babel-node --extensions '.js,.jsx,.ts,.tsx'",
"about:dev": "//// Runs the API server - the course catalog API",
"dev": "NODE_ENV=dev node --watch $(yarn babel-node-ts graphql/index.ts)",
"dev": "NODE_ENV=dev yarn babel-node-ts graphql/index.ts",
"about:dev:notifs": "//// Runs the API server along with the notifications server",
"dev:notifs": "ENABLE_NOTIFS=true yarn dev",
"about:scrape": "//// Scrapes ALL of the latest class data from Banner",
Expand Down Expand Up @@ -64,8 +64,8 @@
"@babel/core": "^7.10.2",
"@babel/node": "^7.0.0",
"@babel/register": "^7.0.0",
"@elastic/elasticsearch": "7.17.0",
"@prisma/client": "6",
"@opensearch-project/opensearch": "^3.3.0",
"@prisma/client": "5.22.0",
"@typescript-eslint/typescript-estree": "^8.10.0",
"amplitude": "^6.0.0",
"apollo-server": "^3.13.0",
Expand Down
14 changes: 7 additions & 7 deletions utils/elastic.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* eslint-disable no-underscore-dangle */
/*
* This file is part of Search NEU and licensed under AGPL3.
* See the license file in the root folder for details.
*/

import { Client } from "@elastic/elasticsearch";
import { Client as OsClient, errors } from "@opensearch-project/opensearch";
import pMap from "p-map";
import _ from "lodash";
import macros from "./macros";
Expand All @@ -16,11 +15,12 @@ import {
} from "../types/searchTypes";
import employeeMap from "../scrapers/employees/employeeMapping.json";
import classMap from "../scrapers/classes/classMapping.json";
import { ResponseError } from "@elastic/elasticsearch/lib/errors";
import { Search_Request } from "@opensearch-project/opensearch/api";

// TODO: The localhost should NOT be hardcoded in!
const URL: string =
macros.getEnvVariable("elasticURL") || "http://localhost:9200";
const client = new Client({ node: URL });
const client = new OsClient({ node: URL });

const BULKSIZE = 2000;
/**
Expand Down Expand Up @@ -287,7 +287,7 @@ export class Elastic {
index: index,
from: from,
size: size,
body: body,
body: body as Search_Request["body"],
});
}

Expand All @@ -298,7 +298,7 @@ export class Elastic {
multiQuery.push({ index });
multiQuery.push(query);
}
return client.msearch({ body: multiQuery });
return client.msearch({ body: multiQuery }) as unknown as EsMultiResult;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: unavoidable cast?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

uhhh for now. There is a branch somewhere on this repo where I have been fixing all the type errs (there are like 400+ in the repo). its been a while so I don't remember why but i dont like doing that either so im sure it was necessary


closeClient(): void {
Expand All @@ -325,7 +325,7 @@ export class Elastic {
}

// If it's a 429, we'll get a ResponseError
if (e instanceof ResponseError) {
if (e instanceof errors.ResponseError) {
macros.warn("Request failed - retrying...");
// Each time, we want to wait a little longer
const timeoutMs = (i + 1) * RETRY_TIME_MULTIPLIER;
Expand Down
Loading
Loading