Skip to content

chg(opensearch): drop unknown fields instead of auto-creating#2690

Merged
gbirman merged 3 commits into
mainfrom
opensearch-drop-unknown-fields
Apr 20, 2026
Merged

chg(opensearch): drop unknown fields instead of auto-creating#2690
gbirman merged 3 commits into
mainfrom
opensearch-drop-unknown-fields

Conversation

@gbirman
Copy link
Copy Markdown
Contributor

@gbirman gbirman commented Apr 20, 2026

Summary

Adds dynamic: 'false' to all OpenSearch index mappings (channels, documents, chats, emails, emails_v2) so writes with fields not in the schema are stored in _source but not indexed — no more accidental auto-mapping of unknown fields.

Note: false drops unknown fields silently. If we want writes to fail loudly on unknown fields instead, swap to strict.

Im running the update manually

Set dynamic=false on all index mappings (channels, documents, chats,
emails, emails_v2) so writes with fields not in the schema are stored
in _source but not indexed. Adds a set_dynamic_false.ts migration
script to apply this setting to existing indices.
@gbirman gbirman requested a review from a team as a code owner April 20, 2026 20:56
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 20, 2026

📝 Walkthrough

Walkthrough

These changes disable dynamic field creation across OpenSearch indices by adding dynamic: 'false' configuration to index mappings in creation scripts and introducing a new runtime script to update existing indices.

Changes

Cohort / File(s) Summary
Index Mapping Initialization
infra/stacks/opensearch/helpers/scripts/create_emails_v2.ts, infra/stacks/opensearch/helpers/scripts/create_indices.ts
Added dynamic: 'false' configuration to OpenSearch index mappings during index creation for emails_v2, CHANNEL, DOCUMENT, CHAT, and EMAIL indices to prevent dynamic field creation when new fields are indexed.
Dynamic Field Configuration Script
infra/stacks/opensearch/helpers/scripts/set_dynamic_false.ts
New utility script that loads environment variables, initializes an OpenSearch client, and applies dynamic: 'false' mapping to existing indices (CHAT, DOCUMENT, EMAIL, CHANNEL, emails_v2) with support for DRY-RUN and LIVE execution modes.
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title follows conventional commits format with 'chg:' prefix and clearly describes the main change: disabling dynamic field creation in OpenSearch indices.
Description check ✅ Passed The PR description clearly explains the changes: adding dynamic: 'false' to OpenSearch index mappings to prevent auto-creation of unknown fields, with details on behavior differences.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

@github-actions github-actions Bot added the infra label Apr 20, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@infra/stacks/opensearch/helpers/scripts/set_dynamic_false.ts`:
- Around line 12-18: Extract the literal 'emails_v2' into a shared constant
named EMAIL_INDEX_V2 in the project's helpers/constants module and replace the
hard-coded string in the INDICES array with an import of EMAIL_INDEX_V2; then
update the other location that currently defines EMAIL_INDEX_V2 (the
create_emails_v2 module) to import that same EMAIL_INDEX_V2 constant instead of
redeclaring it so both the INDICES constant and create_emails_v2 reference a
single source of truth.
🪄 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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c5930536-afbf-4244-bff7-68ed815cfc3c

📥 Commits

Reviewing files that changed from the base of the PR and between 80ea6e6 and e084934.

📒 Files selected for processing (3)
  • infra/stacks/opensearch/helpers/scripts/create_emails_v2.ts
  • infra/stacks/opensearch/helpers/scripts/create_indices.ts
  • infra/stacks/opensearch/helpers/scripts/set_dynamic_false.ts

Comment on lines +12 to +18
const INDICES = [
CHAT_INDEX,
DOCUMENT_INDEX,
EMAIL_INDEX,
CHANNEL_INDEX,
'emails_v2',
];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Extract 'emails_v2' to a shared constant to avoid string duplication.

The literal 'emails_v2' is also defined as EMAIL_INDEX_V2 in create_emails_v2.ts (line 6). Promote it to helpers/constants.ts alongside the other *_INDEX names so both scripts reference a single source of truth — this prevents drift if the index name ever changes.

♻️ Suggested change

In infra/stacks/opensearch/helpers/constants.ts:

 const CHAT_INDEX = 'chats';
 const DOCUMENT_INDEX = 'documents';
 const EMAIL_INDEX = 'emails';
+const EMAIL_INDEX_V2 = 'emails_v2';
 const CHANNEL_INDEX = 'channels';

-export { CHAT_INDEX, DOCUMENT_INDEX, EMAIL_INDEX, CHANNEL_INDEX };
+export { CHAT_INDEX, DOCUMENT_INDEX, EMAIL_INDEX, EMAIL_INDEX_V2, CHANNEL_INDEX };

Then in this file:

 import {
   CHANNEL_INDEX,
   CHAT_INDEX,
   DOCUMENT_INDEX,
   EMAIL_INDEX,
+  EMAIL_INDEX_V2,
   IS_DRY_RUN,
 } from '../constants';

 const INDICES = [
   CHAT_INDEX,
   DOCUMENT_INDEX,
   EMAIL_INDEX,
   CHANNEL_INDEX,
-  'emails_v2',
+  EMAIL_INDEX_V2,
 ];

And update create_emails_v2.ts to import EMAIL_INDEX_V2 from constants rather than redeclaring it locally.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@infra/stacks/opensearch/helpers/scripts/set_dynamic_false.ts` around lines 12
- 18, Extract the literal 'emails_v2' into a shared constant named
EMAIL_INDEX_V2 in the project's helpers/constants module and replace the
hard-coded string in the INDICES array with an import of EMAIL_INDEX_V2; then
update the other location that currently defines EMAIL_INDEX_V2 (the
create_emails_v2 module) to import that same EMAIL_INDEX_V2 constant instead of
redeclaring it so both the INDICES constant and create_emails_v2 reference a
single source of truth.

@gbirman gbirman merged commit 8716510 into main Apr 20, 2026
22 checks passed
@gbirman gbirman deleted the opensearch-drop-unknown-fields branch April 20, 2026 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant