Skip to content

Harden Elasticsearch indexing and search for larger module corpora #4464

Description

@jloh02

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions