Skip to content

refactor: update Elasticsearch and Typesense db index upsert#1405

Merged
alexcos20 merged 2 commits into
mainfrom
feat/db-index-upsert-fix
Jul 9, 2026
Merged

refactor: update Elasticsearch and Typesense db index upsert#1405
alexcos20 merged 2 commits into
mainfrom
feat/db-index-upsert-fix

Conversation

@AdriGeorge

@AdriGeorge AdriGeorge commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Fixes # .

Changes proposed in this PR:

update Elasticsearch and Typesense database methods for document indexing and upserting

Summary by CodeRabbit

  • Bug Fixes
    • Improved DDO persistence: Elasticsearch updates now re-index the full document to replace existing records more reliably.
    • Improved DDO persistence: Typesense updates now use upsert to create or replace documents consistently.
    • After successful writes, stale copies of the same DDO id are removed from other configured schemas across search backends.
    • Kept existing validation and fallback behavior for error scenarios.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5e561de8-928c-49cf-bbb9-1e9a357cef19

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

DDO updates in Elasticsearch and Typesense now write full documents, and each update removes stale copies of the same DDO id from other configured schemas after a successful write.

Changes

DDO Update Persistence Change

Layer / File(s) Summary
Elasticsearch update and cleanup
src/components/database/ElasticSearchDatabase.ts
update now calls client.index with the full ddo body, then deletes the same id from other Elasticsearch schemas; the existing normalization and 404 fallback flow remain.
Typesense upsert and cleanup
src/components/database/typesense.ts, src/components/database/TypesenseDatabase.ts
TypesenseDocuments adds upsert(document) with a document guard and POST action, and TypesenseDdoDatabase.update now uses it before deleting stale copies from other Typesense schemas.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: refactoring the update/upsert behavior for both Elasticsearch and Typesense database indexing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/db-index-upsert-fix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/database/ElasticSearchDatabase.ts`:
- Around line 781-784: The DDO write path in ElasticSearchDatabase.updateDDO
currently only indexes into the target schema via client.index, so stale copies
can remain in other DDO indices after a schema/version change. After a
successful index operation, update the updateDDO flow to also remove the
document from the other DDO indices using the existing Elasticsearch client
helpers and schema/index handling in ElasticSearchDatabase. Make sure the
cleanup is tied to the same ddo.id so only the previous cross-schema copies are
removed.

In `@src/components/database/TypesenseDatabase.ts`:
- Line 646: In TypesenseDatabase’s document write path around the upsert() call,
schema moves can leave stale copies behind in older collections. After the write
succeeds, remove the same document ID from the non-target collections so a DDO
does not remain duplicated across schemas and later surface in
search()/retrieve(). Use the existing TypesenseDatabase collection/document
handling to locate the target write flow and add the cleanup logic there.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3924e9d2-bc1f-4fba-92b7-b4deade6744b

📥 Commits

Reviewing files that changed from the base of the PR and between f274568 and 735d169.

📒 Files selected for processing (3)
  • src/components/database/ElasticSearchDatabase.ts
  • src/components/database/TypesenseDatabase.ts
  • src/components/database/typesense.ts

Comment thread src/components/database/ElasticSearchDatabase.ts
Comment thread src/components/database/TypesenseDatabase.ts Outdated
@alexcos20

Copy link
Copy Markdown
Member

/run-security-scan

@alexcos20 alexcos20 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AI automated code review (Gemini 3).

Overall risk: low

Summary:
The PR correctly updates database write operations to use 'upsert' semantics (using index in Elasticsearch and upsert in Typesense). This prevents 'document not found' errors when updating non-existent records, ensures idempotent writes, and aligns the behavior across both database implementations.

Comments:
• [INFO][performance] Excellent change. Switching from update to index provides true upsert (create or replace) semantics. Using index is also generally more performant than update with doc_as_upsert for full document replacements because it avoids the internal fetch-and-merge step. Removing the { doc: ddo } wrapper is correct here as index expects the raw document in the body.
• [INFO][other] Switching to upsert(ddo) successfully aligns the Typesense implementation with the Elasticsearch changes, ensuring consistent behavior across different storage backends.
• [INFO][style] The new upsert wrapper method looks clean. Retaining the async keyword here (along with the eslint exception) is a good practice—it ensures that the synchronous throw new Error('No document provided') will properly reject the returned Promise rather than throwing a synchronous exception. LGTM!

@alexcos20

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@alexcos20
alexcos20 self-requested a review July 9, 2026 13:48
@alexcos20
alexcos20 merged commit 6cb55b5 into main Jul 9, 2026
68 of 76 checks passed
@alexcos20
alexcos20 deleted the feat/db-index-upsert-fix branch July 9, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants