Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat: create new emails index (#1935)
gbirman82676359659f
diff --git a/infra/stacks/opensearch/helpers/scripts/create_emails_v2.ts b/infra/stacks/opensearch/helpers/scripts/create_emails_v2.tsnew file mode 100644index 0000000000..849500bcba--- /dev/null+++ b/infra/stacks/opensearch/helpers/scripts/create_emails_v2.ts@@ -0,0 +1,97 @@+require('dotenv').config();++import { client } from '../client';+import { IS_DRY_RUN, SHARD_SETTINGS } from '../constants';++const EMAIL_INDEX_V2 = 'emails_v2';++const EMAIL_MAPPINGS = {+ properties: {+ entity_id: { type: 'keyword' as const },+ message_id: { type: 'keyword' as const },+ thread_id: { type: 'keyword' as const },+ user_id: { type: 'keyword' as const },+ link_id: { type: 'keyword' as const },+ sender: { type: 'keyword' as const },+ recipients: { type: 'keyword' as const },+ cc: { type: 'keyword' as const },+ bcc: { type: 'keyword' as const },+ reply_to: {+ type: 'keyword' as const,+ index: true,+ doc_values: true,+ },+ labels: { type: 'keyword' as const, index: false },+ subject: {+ type: 'text' as const,+ fields: { keyword: { type: 'keyword' as const, ignore_above: 50 } },+ },+ content: { type: 'text' as const, analyzer: 'standard' },+ sender_name: { type: 'text' as const, analyzer: 'standard' },+ recipient_names: { type: 'text' as const, analyzer: 'standard' },+ cc_names: { type: 'text' as const, analyzer: 'standard' },+ bcc_names: { type: 'text' as const, analyzer: 'standard' },+ sent_at: { type: 'date' as const, index: false },+ sent_at_seconds: {+ type: 'date' as const,+ index: false,+ format: 'epoch_second',+ },+ updated_at: { type: 'date' as const, index: false },+ updated_at_seconds: {+ type: 'date' as const,+ index: false,+ format: 'epoch_second',+ },+ },+};++async function createEmailsV2(dryRun: boolean) {+ const opensearchClient = client();++ console.log('\n' + '='.repeat(60));+ console.log(+ `Create ${EMAIL_INDEX_V2} index ${dryRun ? '(DRY-RUN MODE)' : '(LIVE MODE)'}`+ );+ console.log('='.repeat(60));++ const exists = (+ await opensearchClient.indices.exists({ index: EMAIL_INDEX_V2 })+ ).body;++ if (exists) {+ console.log(`Index "${EMAIL_INDEX_V2}" already exists. Aborting.`);+ return;+ }++ if (dryRun) {+ console.log('\n[DRY-RUN] Would create index with settings:');+ console.log(JSON.stringify(SHARD_SETTINGS, null, 2));+ console.log('\n[DRY-RUN] Would create index with mappings:');+ console.log(JSON.stringify(EMAIL_MAPPINGS, null, 2));+ console.log('\nTo run for real, set DRY_RUN=false');+ return;+ }++ await opensearchClient.indices.create({+ index: EMAIL_INDEX_V2,+ body: {+ settings: SHARD_SETTINGS,+ mappings: EMAIL_MAPPINGS,+ },+ });++ console.log(`\nCreated ${EMAIL_INDEX_V2}`);++ console.log('\n' + '='.repeat(60));+ console.log('Done! Next steps:');+ console.log(' 1. Deploy code that uses emails_alias');+ console.log(+ ' 2. Swap alias: POST /_aliases { "actions": [{ "remove": { "index": "emails", "alias": "emails_alias" }}, { "add": { "index": "emails_v2", "alias": "emails_alias" }}] }'+ );+ console.log(' 3. Backfill emails_v2');+ console.log(' 4. Delete old emails index');+ console.log('='.repeat(60));+}++createEmailsV2(IS_DRY_RUN);diff --git a/rust/cloud-storage/models_opensearch/src/lib.rs b/rust/cloud-storage/models_opensearch/src/lib.rsindex d516373380..f3de0202f3 100644--- a/rust/cloud-storage/models_opensearch/src/lib.rs+++ b/rust/cloud-storage/models_opensearch/src/lib.rs@@ -14,6 +14,7 @@ pub enum SearchIndex {/// The document indexDocuments,/// The email index+ #[strum(serialize = "emails_alias")]Emails,/// The project indexProjects,@@ -49,6 +50,20 @@ pub enum SearchEntityType {Projects,}+impl SearchEntityType {+ /// Returns the index name to use for OpenSearch queries.+ /// This may differ from the enum's string representation when using aliases.+ pub fn index_name(&self) -> &'static str {+ match self {+ Self::Channels => "channels",+ Self::Chats => "chats",+ Self::Documents => "documents",+ Self::Emails => "emails_alias",+ Self::Projects => "projects",+ }+ }+}+impl From<SearchEntityType> for SearchIndex {fn from(value: SearchEntityType) -> Self {match value {diff --git a/rust/cloud-storage/opensearch_client/src/search/builder.rs b/rust/cloud-storage/opensearch_client/src/search/builder.rsindex 9cb3ddbd5d..2021e52a6e 100644--- a/rust/cloud-storage/opensearch_client/src/search/builder.rs+++ b/rust/cloud-storage/opensearch_client/src/search/builder.rs@@ -291,7 +291,7 @@ impl<T: SearchQueryConfig> SearchQueryBuilder<T> {access_bool_query.filter(filter_bool_query);// Only search on the provided index- access_bool_query.filter(QueryType::term("_index", T::ENTITY_INDEX.as_ref()));+ access_bool_query.filter(QueryType::term("_index", T::ENTITY_INDEX.index_name()));Ok(access_bool_query)}diff --git a/rust/cloud-storage/opensearch_client/src/search/emails/test.rs b/rust/cloud-storage/opensearch_client/src/search/emails/test.rsindex 9405e1213b..0504255aed 100644--- a/rust/cloud-storage/opensearch_client/src/search/emails/test.rs+++ b/rust/cloud-storage/opensearch_client/src/search/emails/test.rs@@ -49,7 +49,7 @@ fn test_build_search_request() -> anyhow::Result<()> {},{"term": {- "_index": "emails"+ "_index": "emails_alias"}},{diff --git a/rust/cloud-storage/opensearch_client/src/search/unified/test.rs b/rust/cloud-storage/opensearch_client/src/search/unified/test.rsindex c8aac11151..4fdccc5db7 100644--- a/rust/cloud-storage/opensearch_client/src/search/unified/test.rs+++ b/rust/cloud-storage/opensearch_client/src/search/unified/test.rs@@ -550,7 +550,7 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {},{"term": {- "_index": "emails"+ "_index": "emails_alias"}},{