nusmodifications / nusmodifications/nusmods

Harden Elasticsearch indexing and search for larger module corpora

Open
#4,464 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
689
Forks
364
Avg merge
7h 5m
Merged PRs (30d)
14

Description

Problem

The timeout increase in #4463 is an immediate mitigation, but the scraper/search integration still has several size-related assumptions that are now brittle with the current corpus size.

Observed production context:

  • modules_v2 has about 21,096 documents.
  • moduleInfo bulk indexing is sent as one large request, about 18.5 MB.
  • ElasticPersist.getModuleCodes() fetches at most 20,000 docs in a single search.
  • modules_v2 has index.max_result_window = 20000.
  • Frontend pagination/random-course paths can request beyond the ES result window and receive HTTP 400.
  • createIndex() assumes a specific error shape and can throw Cannot read properties of undefined (reading 'type') for other ES errors.

Proposed work

  • Chunk scraper moduleInfo bulk writes by document count and/or byte size.
  • Add retry/backoff for transient ES timeout/connection failures.
  • Replace getModuleCodes() single size: 20000 search with scroll/search-after so cleanup sees all existing documents.
  • Fix frontend deep pagination/random-course behavior so it does not request beyond index.max_result_window, or move those paths to a cursor/search-after-safe design.
  • Harden ES error handling in createIndex() and delete paths so unexpected ES/network errors are logged clearly without masking the original cause.

Notes

This is intentionally separate from the timeout mitigation PR so the production scraper can be unblocked first.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing scraper moduleInfo bulk indexing, ElasticPersist.getModuleCodes(), createIndex(), delete paths, and the frontend pagination/random-course paths named in the issue. Verify the current Elasticsearch request limits and error behavior before splitting the work into focused changes. Done means large corpora index and clean up reliably, deep pagination avoids result-window failures, and unexpected Elasticsearch errors retain clear original causes.

Written by the indexing model from the issue text.

Assessment

Tech stack
elasticsearch, javascript
Domain
backend, frontend, search
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.