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(search_processing_service): process UpdateEntityName messages (#279)
Will Hutchinson1c0fe25e6034
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lockindex f2080a92a0..d8e3ad0b0b 100644--- a/rust/cloud-storage/Cargo.lock+++ b/rust/cloud-storage/Cargo.lock@@ -4742,6 +4742,7 @@ dependencies = ["model","model-entity","models_dcs",+ "models_opensearch","models_pagination","models_permissions","models_search",@@ -5389,6 +5390,15 @@ dependencies = ["uuid",]+[[package]]+name = "models_opensearch"+version = "0.1.0"+dependencies = [+ "serde",+ "serde_json",+ "strum",+]+[[package]]name = "models_pagination"version = "0.1.0"@@ -5438,6 +5448,7 @@ version = "0.1.0"dependencies = ["chrono","item_filters",+ "models_opensearch","opensearch_client","schemars","serde",@@ -5779,6 +5790,7 @@ dependencies = ["anyhow","chrono","macro_entrypoint",+ "models_opensearch","opensearch","opensearch_query_builder","serde",@@ -8182,6 +8194,7 @@ dependencies = ["chrono","model","models_email",+ "models_opensearch","serde","serde_json","strum",diff --git a/rust/cloud-storage/Cargo.toml b/rust/cloud-storage/Cargo.tomlindex 3aaa6ccf23..173e2e3a17 100644--- a/rust/cloud-storage/Cargo.toml+++ b/rust/cloud-storage/Cargo.toml@@ -67,6 +67,7 @@ members = ["models_dcs","models_email","models_metering",+ "models_opensearch","models_pagination","models_permissions","models_properties",diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-34a1c3b64fdb985b5e78d815f8fac33efbd25ad5cb6854e9fe3949518f530570.json b/rust/cloud-storage/macro_db_client/.sqlx/query-34a1c3b64fdb985b5e78d815f8fac33efbd25ad5cb6854e9fe3949518f530570.jsonnew file mode 100644index 0000000000..32c5fe0adb--- /dev/null+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-34a1c3b64fdb985b5e78d815f8fac33efbd25ad5cb6854e9fe3949518f530570.json@@ -0,0 +1,22 @@+{+ "db_name": "PostgreSQL",+ "query": "\n SELECT\n c.name as \"name?\"\n FROM\n \"comms_channels\" c\n WHERE\n c.id = $1\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "name?",+ "type_info": "Varchar"+ }+ ],+ "parameters": {+ "Left": [+ "Uuid"+ ]+ },+ "nullable": [+ true+ ]+ },+ "hash": "34a1c3b64fdb985b5e78d815f8fac33efbd25ad5cb6854e9fe3949518f530570"+}diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-4330d1613cce138c4ad80ab77be5d5974752e684b9350a86e77098cff910849c.json b/rust/cloud-storage/macro_db_client/.sqlx/query-4330d1613cce138c4ad80ab77be5d5974752e684b9350a86e77098cff910849c.jsonnew file mode 100644index 0000000000..7f2b0568cb--- /dev/null+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-4330d1613cce138c4ad80ab77be5d5974752e684b9350a86e77098cff910849c.json@@ -0,0 +1,22 @@+{+ "db_name": "PostgreSQL",+ "query": "\n SELECT\n c.name\n FROM\n \"Chat\" c\n WHERE\n c.id = $1\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "name",+ "type_info": "Text"+ }+ ],+ "parameters": {+ "Left": [+ "Text"+ ]+ },+ "nullable": [+ false+ ]+ },+ "hash": "4330d1613cce138c4ad80ab77be5d5974752e684b9350a86e77098cff910849c"+}diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-b10688248a9a0a8577b81b6e5e3ac178ff73f084e219e6e77814400f7af45c70.json b/rust/cloud-storage/macro_db_client/.sqlx/query-b10688248a9a0a8577b81b6e5e3ac178ff73f084e219e6e77814400f7af45c70.jsonnew file mode 100644index 0000000000..9251692ab1--- /dev/null+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-b10688248a9a0a8577b81b6e5e3ac178ff73f084e219e6e77814400f7af45c70.json@@ -0,0 +1,22 @@+{+ "db_name": "PostgreSQL",+ "query": "\n SELECT\n d.name\n FROM\n \"Document\" d\n WHERE\n d.id = $1\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "name",+ "type_info": "Text"+ }+ ],+ "parameters": {+ "Left": [+ "Text"+ ]+ },+ "nullable": [+ false+ ]+ },+ "hash": "b10688248a9a0a8577b81b6e5e3ac178ff73f084e219e6e77814400f7af45c70"+}diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-b3766104e7a069d3c092841e0d5944beeff5f96be5d9a98eb1645202f585da81.json b/rust/cloud-storage/macro_db_client/.sqlx/query-b3766104e7a069d3c092841e0d5944beeff5f96be5d9a98eb1645202f585da81.jsonnew file mode 100644index 0000000000..a46188620b--- /dev/null+++ b/rust/cloud-storage/macro_db_client/.sqlx/query-b3766104e7a069d3c092841e0d5944beeff5f96be5d9a98eb1645202f585da81.json@@ -0,0 +1,22 @@+{+ "db_name": "PostgreSQL",+ "query": "\n SELECT\n e.subject\n FROM\n \"email_messages\" e\n WHERE\n e.thread_id = $1\n LIMIT 1\n ",+ "describe": {+ "columns": [+ {+ "ordinal": 0,+ "name": "subject",+ "type_info": "Text"+ }+ ],+ "parameters": {+ "Left": [+ "Uuid"+ ]+ },+ "nullable": [+ true+ ]+ },+ "hash": "b3766104e7a069d3c092841e0d5944beeff5f96be5d9a98eb1645202f585da81"+}diff --git a/rust/cloud-storage/macro_db_client/Cargo.toml b/rust/cloud-storage/macro_db_client/Cargo.tomlindex d6413c28c7..ce63b9f64c 100644--- a/rust/cloud-storage/macro_db_client/Cargo.toml+++ b/rust/cloud-storage/macro_db_client/Cargo.toml@@ -37,3 +37,4 @@ tracing = { workspace = true }uuid = { workspace = true }user_quota = { path = "../user_quota" }macro_user_id = { path = "../macro_user_id" }+models_opensearch = { path = "../models_opensearch" }diff --git a/rust/cloud-storage/macro_db_client/fixtures/get_entity_name.sql b/rust/cloud-storage/macro_db_client/fixtures/get_entity_name.sqlnew file mode 100644index 0000000000..a257d4c310--- /dev/null+++ b/rust/cloud-storage/macro_db_client/fixtures/get_entity_name.sql@@ -0,0 +1,60 @@+INSERT INTO macro_user (id, email, stripe_customer_id, username) VALUES+('11111111-1111-1111-1111-111111111111', '[email protected]', 'cus_1234', 'user');++INSERT INTO "User" ("id", "email", "name", "stripeCustomerId", macro_user_id) VALUES+('macro|[email protected]', '[email protected]', 'User', 'cus_1234', '11111111-1111-1111-1111-111111111111');++INSERT INTO "Document" ("id", "name", "fileType", "owner", "createdAt", "updatedAt")+VALUES+ ('11111111-1111-1111-1111-111111111111', 'document', 'pdf', 'macro|[email protected]', '2019-10-16 00:00:00', '2019-10-16 00:00:00');++INSERT INTO "Chat" ("id", "name", "userId", "createdAt", "updatedAt")+VALUES+ ('11111111-1111-1111-1111-111111111111', 'chat', 'macro|[email protected]', '2019-10-16 01:01:00', '2019-10-16 01:01:00');++INSERT INTO comms_channels (id, name, channel_type, org_id, owner_id)+VALUES ('11111111-1111-1111-1111-111111111111', 'channel', 'public', NULL, 'macro|[email protected]');++INSERT INTO email_links (id, macro_id, fusionauth_user_id, email_address, provider, is_sync_active, created_at,+ updated_at)+VALUES ('11111111-1111-1111-1111-111111111111', 'macro|[email protected]', '11111111-1111-1111-1111-111111111111',+ '[email protected]', 'GMAIL', true, '2025-11-11 17:48:26.664688 +00:00',+ '2025-11-11 17:48:26.664688 +00:00');++-- Thread 1: used for condition 1 (is_sent = true)+INSERT INTO email_threads (id, link_id, inbox_visible, is_read, created_at, updated_at)+VALUES ('11111111-1111-1111-1111-111111111111',+ '11111111-1111-1111-1111-111111111111',+ false,+ false,+ NOW(),+ NOW());++INSERT INTO email_messages (id,+ thread_id,+ link_id,+ provider_id,+ is_sent,+ from_contact_id,+ internal_date_ts,+ has_attachments,+ is_read,+ is_starred,+ is_draft,+ created_at,+ updated_at,+ subject)+VALUES ('11111111-1111-1111-1111-111111111111',+ '11111111-1111-1111-1111-111111111111',+ '11111111-1111-1111-1111-111111111111',+ 'provider-msg-101',+ TRUE,+ NULL,+ NOW(),+ true,+ false,+ false,+ false,+ NOW(),+ NOW(),+ 'subject');diff --git a/rust/cloud-storage/macro_db_client/src/entity_name.rs b/rust/cloud-storage/macro_db_client/src/entity_name.rsnew file mode 100644index 0000000000..21e9404cd9--- /dev/null+++ b/rust/cloud-storage/macro_db_client/src/entity_name.rs@@ -0,0 +1,85 @@+use models_opensearch::SearchEntityType;++/// Gets the entity name for the provided entity id and entity type+#[tracing::instrument(skip(db), err)]+pub async fn get_entity_name(+ db: &sqlx::PgPool,+ entity_id: &uuid::Uuid,+ entity_type: &SearchEntityType,+) -> anyhow::Result<Option<String>> {+ let name: Option<String> = match entity_type {+ SearchEntityType::Chats => {+ sqlx::query!(+ r#"+ SELECT+ c.name+ FROM+ "Chat" c+ WHERE+ c.id = $1+ "#,+ &entity_id.to_string(),+ )+ .map(|row| Some(row.name))+ .fetch_one(db)+ .await?+ }+ SearchEntityType::Documents => {+ sqlx::query!(+ r#"+ SELECT+ d.name+ FROM+ "Document" d+ WHERE+ d.id = $1+ "#,+ &entity_id.to_string(),+ )+ .map(|row| Some(row.name))+ .fetch_one(db)+ .await?+ }+ SearchEntityType::Emails => {+ sqlx::query!(+ r#"+ SELECT+ e.subject+ FROM+ "email_messages" e+ WHERE+ e.thread_id = $1+ LIMIT 1+ "#,+ entity_id,+ )+ .map(|row| row.subject)+ .fetch_one(db)+ .await?+ }+ SearchEntityType::Channels => {+ sqlx::query!(+ r#"+ SELECT+ c.name as "name?"+ FROM+ "comms_channels" c+ WHERE+ c.id = $1+ "#,+ entity_id,+ )+ .map(|row| row.name)+ .fetch_one(db)+ .await?+ }+ _ => {+ anyhow::bail!("entity type not supported");+ }+ };++ Ok(name)+}++#[cfg(test)]+mod test;diff --git a/rust/cloud-storage/macro_db_client/src/entity_name/test.rs b/rust/cloud-storage/macro_db_client/src/entity_name/test.rsnew file mode 100644index 0000000000..7f44e9731e--- /dev/null+++ b/rust/cloud-storage/macro_db_client/src/entity_name/test.rs@@ -0,0 +1,36 @@+use super::*;++#[sqlx::test(fixtures(path = "../../fixtures", scripts("get_entity_name")))]+async fn test_get_entity_name(pool: sqlx::Pool<sqlx::Postgres>) -> anyhow::Result<()> {+ let entity_id = uuid::Uuid::parse_str("11111111-1111-1111-1111-111111111111")?;+ let entity_name = get_entity_name(&pool, &entity_id, &SearchEntityType::Documents).await?;+ assert_eq!(entity_name, Some("document".to_string()));++ let entity_name = get_entity_name(&pool, &entity_id, &SearchEntityType::Chats).await?;+ assert_eq!(entity_name, Some("chat".to_string()));++ let entity_name = get_entity_name(&pool, &entity_id, &SearchEntityType::Channels).await?;+ assert_eq!(entity_name, Some("channel".to_string()));++ let entity_name = get_entity_name(&pool, &entity_id, &SearchEntityType::Emails).await?;+ assert_eq!(entity_name, Some("subject".to_string()));++ let result = get_entity_name(&pool, &entity_id, &SearchEntityType::Projects).await;+ assert!(result.is_err());+ assert_eq!(result.unwrap_err().to_string(), "entity type not supported");++ let result = get_entity_name(+ &pool,+ ¯o_uuid::generate_uuid_v7(),+ &SearchEntityType::Documents,+ )+ .await;++ assert!(result.is_err());+ assert_eq!(+ result.unwrap_err().to_string(),+ "no rows returned by a query that expected to return at least one row"+ );++ Ok(())+}diff --git a/rust/cloud-storage/macro_db_client/src/lib.rs b/rust/cloud-storage/macro_db_client/src/lib.rsindex c5287240ff..31c97d7995 100644--- a/rust/cloud-storage/macro_db_client/src/lib.rs+++ b/rust/cloud-storage/macro_db_client/src/lib.rs@@ -9,6 +9,7 @@ pub mod dcs;pub mod document;pub mod document_text;pub mod docx_unzip;+pub mod entity_name;pub mod experiment;pub mod experiment_log;pub mod history;diff --git a/rust/cloud-storage/models_opensearch/Cargo.toml b/rust/cloud-storage/models_opensearch/Cargo.tomlnew file mode 100644index 0000000000..1852f89f75--- /dev/null+++ b/rust/cloud-storage/models_opensearch/Cargo.toml@@ -0,0 +1,10 @@+[package]+edition = "2024"+name = "models_opensearch"+publish = false+version = "0.1.0"++[dependencies]+serde = { workspace = true }+serde_json = { workspace = true }+strum = { workspace = true }diff --git a/rust/cloud-storage/models_opensearch/src/lib.rs b/rust/cloud-storage/models_opensearch/src/lib.rsnew file mode 100644index 0000000000..d516373380--- /dev/null+++ b/rust/cloud-storage/models_opensearch/src/lib.rs@@ -0,0 +1,62 @@+#![deny(missing_docs)]+//! This crate contains models used by opensearch.+//! This crate should never contain utoipa or any service-level models.+//! This is purely a crate containing models used for opensearch directly.++/// Enum for all the search indices+#[derive(Debug, Clone, Hash, Eq, PartialEq, strum::Display, strum::EnumString, strum::AsRefStr)]+#[strum(serialize_all = "lowercase")]+pub enum SearchIndex {+ /// The channel index+ Channels,+ /// The chat index+ Chats,+ /// The document index+ Documents,+ /// The email index+ Emails,+ /// The project index+ Projects,+ /// The name index+ Names,+}++/// Enum for all entity search indices+#[derive(+ Debug,+ Clone,+ Hash,+ Eq,+ PartialEq,+ strum::Display,+ strum::EnumString,+ strum::AsRefStr,+ serde::Serialize,+ serde::Deserialize,+)]+#[strum(serialize_all = "lowercase")]+#[serde(rename_all = "lowercase")]+pub enum SearchEntityType {+ /// The channel index+ Channels,+ /// The chat index+ Chats,+ /// The document index+ Documents,+ /// The email index+ Emails,+ /// The project index+ Projects,+}++impl From<SearchEntityType> for SearchIndex {+ fn from(value: SearchEntityType) -> Self {+ match value {+ SearchEntityType::Channels => SearchIndex::Channels,+ SearchEntityType::Chats => SearchIndex::Chats,+ SearchEntityType::Documents => SearchIndex::Documents,+ SearchEntityType::Emails => SearchIndex::Emails,+ SearchEntityType::Projects => SearchIndex::Projects,+ }+ }+}diff --git a/rust/cloud-storage/models_search/Cargo.toml b/rust/cloud-storage/models_search/Cargo.tomlindex 9d81ed02a4..d0e21dc09b 100644--- a/rust/cloud-storage/models_search/Cargo.toml+++ b/rust/cloud-storage/models_search/Cargo.toml@@ -8,6 +8,7 @@ version = "0.1.0"chrono = { workspace = true }item_filters = { path = "../item_filters" }opensearch_client = { path = "../opensearch_client" }+models_opensearch = { path = "../models_opensearch" }schemars = { workspace = true }serde = { workspace = true }serde_json = { workspace = true }diff --git a/rust/cloud-storage/models_search/src/unified.rs b/rust/cloud-storage/models_search/src/unified.rsindex aafdad0278..a65637506f 100644--- a/rust/cloud-storage/models_search/src/unified.rs+++ b/rust/cloud-storage/models_search/src/unified.rs@@ -59,7 +59,7 @@ pub struct UnifiedSearchRequest {pub include: Vec<UnifiedSearchIndex>,}-impl From<UnifiedSearchIndex> for opensearch_client::search::model::SearchIndex {+impl From<UnifiedSearchIndex> for models_opensearch::SearchEntityType {fn from(index: UnifiedSearchIndex) -> Self {match index {UnifiedSearchIndex::Channels => Self::Channels,@@ -74,9 +74,9 @@ impl From<UnifiedSearchIndex> for opensearch_client::search::model::SearchIndex/// Generates the search indices to search over for unified searchpub fn generate_unified_search_indices(include: Vec<UnifiedSearchIndex>,-) -> HashSet<opensearch_client::search::model::SearchIndex> {+) -> HashSet<models_opensearch::SearchEntityType> {if include.is_empty() {- let include: Vec<opensearch_client::search::model::SearchIndex> = [+ let include: Vec<models_opensearch::SearchEntityType> = [UnifiedSearchIndex::Channels,UnifiedSearchIndex::Chats,UnifiedSearchIndex::Documents,diff --git a/rust/cloud-storage/opensearch_client/Cargo.toml b/rust/cloud-storage/opensearch_client/Cargo.tomlindex 4ce21c6329..a0cf0041b6 100644--- a/rust/cloud-storage/opensearch_client/Cargo.toml+++ b/rust/cloud-storage/opensearch_client/Cargo.toml@@ -22,3 +22,4 @@ thiserror = { workspace = true }tracing = { workspace = true }unicode-segmentation = "1.9.0"strum = { workspace = true }+models_opensearch = { path = "../models_opensearch" }diff --git a/rust/cloud-storage/opensearch_client/src/delete/channel.rs b/rust/cloud-storage/opensearch_client/src/delete/channel.rsindex e59408482a..e6122b1762 100644--- a/rust/cloud-storage/opensearch_client/src/delete/channel.rs+++ b/rust/cloud-storage/opensearch_client/src/delete/channel.rs@@ -1,4 +1,6 @@-use crate::{CHANNEL_INDEX, Result, error::OpensearchClientError};+use models_opensearch::SearchIndex;++use crate::{Result, error::OpensearchClientError};/// Deletes all channel messages with the specified channel_id#[tracing::instrument(skip(client))]@@ -12,7 +14,9 @@ pub async fn delete_channel_by_id(client: &opensearch::OpenSearch, channel_id: &});let response = client- .delete_by_query(opensearch::DeleteByQueryParts::Index(&[CHANNEL_INDEX]))+ .delete_by_query(opensearch::DeleteByQueryParts::Index(&[+ SearchIndex::Channels.as_ref(),+ ])).body(query).refresh(true) // Ensure the index reflects changes immediately.send()@@ -76,7 +80,9 @@ pub async fn delete_channel_message_by_id(});let response = client- .delete_by_query(opensearch::DeleteByQueryParts::Index(&[CHANNEL_INDEX]))+ .delete_by_query(opensearch::DeleteByQueryParts::Index(&[+ SearchIndex::Channels.as_ref(),+ ])).body(query).refresh(true) // Ensure the index reflects changes immediately.send()diff --git a/rust/cloud-storage/opensearch_client/src/delete/chat.rs b/rust/cloud-storage/opensearch_client/src/delete/chat.rsindex 04cf53e29c..746246a7c1 100644--- a/rust/cloud-storage/opensearch_client/src/delete/chat.rs+++ b/rust/cloud-storage/opensearch_client/src/delete/chat.rs@@ -1,4 +1,6 @@-use crate::{CHAT_INDEX, Result, error::OpensearchClientError};+use models_opensearch::SearchIndex;++use crate::{Result, error::OpensearchClientError};/// Deletes all chat messages with the specified chat_id#[tracing::instrument(skip(client))]@@ -12,7 +14,9 @@ pub async fn delete_chat_by_id(client: &opensearch::OpenSearch, chat_id: &str) -});let response = client- .delete_by_query(opensearch::DeleteByQueryParts::Index(&[CHAT_INDEX]))+ .delete_by_query(opensearch::DeleteByQueryParts::Index(&[+ SearchIndex::Chats.as_ref()+ ])).body(query).refresh(true) // Ensure the index reflects changes immediately.send()@@ -76,7 +80,9 @@ pub async fn delete_chat_message_by_id(});let response = client- .delete_by_query(opensearch::DeleteByQueryParts::Index(&[CHAT_INDEX]))+ .delete_by_query(opensearch::DeleteByQueryParts::Index(&[+ SearchIndex::Chats.as_ref()+ ])).body(query).refresh(true) // Ensure the index reflects changes immediately.send()@@ -125,7 +131,9 @@ pub async fn delete_chat_by_user_id(client: &opensearch::OpenSearch, user_id: &s});let response = client- .delete_by_query(opensearch::DeleteByQueryParts::Index(&[CHAT_INDEX]))+ .delete_by_query(opensearch::DeleteByQueryParts::Index(&[+ SearchIndex::Chats.as_ref()+ ])).body(query).refresh(true) // Ensure the index reflects changes immediately.send()diff --git a/rust/cloud-storage/opensearch_client/src/delete/document.rs b/rust/cloud-storage/opensearch_client/src/delete/document.rsindex 33a948b1fe..e4dfec50d8 100644--- a/rust/cloud-storage/opensearch_client/src/delete/document.rs+++ b/rust/cloud-storage/opensearch_client/src/delete/document.rs@@ -1,4 +1,6 @@-use crate::{DOCUMENTS_INDEX, Result, error::OpensearchClientError};+use models_opensearch::SearchIndex;++use crate::{Result, error::OpensearchClientError};/// Deletes all document nodes with the specified document_id#[tracing::instrument(skip(client))]@@ -16,7 +18,9 @@ pub async fn delete_document_by_id(});let response = client- .delete_by_query(opensearch::DeleteByQueryParts::Index(&[DOCUMENTS_INDEX]))+ .delete_by_query(opensearch::DeleteByQueryParts::Index(&[+ SearchIndex::Documents.as_ref(),+ ])).body(query).refresh(true) // Ensure the index reflects changes immediately.send()@@ -69,7 +73,9 @@ pub async fn delete_document_by_owner_id(});let response = client- .delete_by_query(opensearch::DeleteByQueryParts::Index(&[DOCUMENTS_INDEX]))+ .delete_by_query(opensearch::DeleteByQueryParts::Index(&[+ SearchIndex::Documents.as_ref(),+ ])).body(query).refresh(true) // Ensure the index reflects changes immediately.send()diff --git a/rust/cloud-storage/opensearch_client/src/delete/email.rs b/rust/cloud-storage/opensearch_client/src/delete/email.rsindex 6c059e03dc..4f74646be9 100644--- a/rust/cloud-storage/opensearch_client/src/delete/email.rs+++ b/rust/cloud-storage/opensearch_client/src/delete/email.rs@@ -1,4 +1,6 @@-use crate::{CHAT_INDEX, Result, error::OpensearchClientError};+use models_opensearch::SearchIndex;++use crate::{Result, error::OpensearchClientError};/// Deletes all email messages with the specified thread_id#[tracing::instrument(skip(client))]@@ -15,7 +17,9 @@ pub async fn delete_email_by_thread_id(});let response = client- .delete_by_query(opensearch::DeleteByQueryParts::Index(&[CHAT_INDEX]))+ .delete_by_query(opensearch::DeleteByQueryParts::Index(&[+ SearchIndex::Emails.as_ref(),+ ])).body(query).refresh(true) // Ensure the index reflects changes immediately.send()@@ -64,7 +68,9 @@ pub async fn delete_email_by_link_id(client: &opensearch::OpenSearch, link_id: &});let response = client- .delete_by_query(opensearch::DeleteByQueryParts::Index(&[CHAT_INDEX]))+ .delete_by_query(opensearch::DeleteByQueryParts::Index(&[+ SearchIndex::Emails.as_ref(),+ ])).body(query).refresh(true) // Ensure the index reflects changes immediately.send()@@ -116,7 +122,9 @@ pub async fn delete_email_message_by_id(});let response = client- .delete_by_query(opensearch::DeleteByQueryParts::Index(&[CHAT_INDEX]))+ .delete_by_query(opensearch::DeleteByQueryParts::Index(&[+ SearchIndex::Emails.as_ref(),+ ])).body(query).refresh(true) // Ensure the index reflects changes immediately.send()@@ -165,7 +173,9 @@ pub async fn delete_email_by_user_id(client: &opensearch::OpenSearch, user_id: &});let response = client- .delete_by_query(opensearch::DeleteByQueryParts::Index(&[CHAT_INDEX]))+ .delete_by_query(opensearch::DeleteByQueryParts::Index(&[+ SearchIndex::Emails.as_ref(),+ ])).body(query).refresh(true) // Ensure the index reflects changes immediately.send()diff --git a/rust/cloud-storage/opensearch_client/src/delete/project.rs b/rust/cloud-storage/opensearch_client/src/delete/project.rsindex 549f67544b..6ead3e4c59 100644--- a/rust/cloud-storage/opensearch_client/src/delete/project.rs+++ b/rust/cloud-storage/opensearch_client/src/delete/project.rs@@ -1,10 +1,15 @@-use crate::{PROJECT_INDEX, Result, error::OpensearchClientError};+use models_opensearch::SearchIndex;++use crate::{Result, error::OpensearchClientError};/// Deletes a project by its ID#[tracing::instrument(skip(client))]pub async fn delete_project_by_id(client: &opensearch::OpenSearch, project_id: &str) -> Result<()> {let response = client- .delete(opensearch::DeleteParts::IndexId(PROJECT_INDEX, project_id))+ .delete(opensearch::DeleteParts::IndexId(+ SearchIndex::Projects.as_ref(),+ project_id,+ )).refresh(opensearch::params::Refresh::True) // Ensure the index reflects changes immediately.send().await@@ -66,7 +71,9 @@ pub async fn delete_project_bulk_ids(});let response = client- .delete_by_query(opensearch::DeleteByQueryParts::Index(&[PROJECT_INDEX]))+ .delete_by_query(opensearch::DeleteByQueryParts::Index(&[+ SearchIndex::Projects.as_ref(),+ ])).body(query).refresh(true).send()@@ -120,7 +127,9 @@ pub async fn delete_projects_by_user_id(});let response = client- .delete_by_query(opensearch::DeleteByQueryParts::Index(&[PROJECT_INDEX]))+ .delete_by_query(opensearch::DeleteByQueryParts::Index(&[+ SearchIndex::Projects.as_ref(),+ ])).body(query).refresh(true) // Ensure the index reflects changes immediately.send()diff --git a/rust/cloud-storage/opensearch_client/src/document.rs b/rust/cloud-storage/opensearch_client/src/document.rsindex f832130b16..eab391c7bc 100644--- a/rust/cloud-storage/opensearch_client/src/document.rs+++ b/rust/cloud-storage/opensearch_client/src/document.rs@@ -1,8 +1,8 @@use crate::{- OpensearchClient, Result, delete, get_document,+ OpensearchClient, Result, delete,search::{self,- documents::{DocumentIndex, DocumentSearchResponse, search_documents},+ documents::{DocumentSearchResponse, search_documents},},upsert::{self, document::UpsertDocumentArgs},};@@ -32,12 +32,6 @@ impl OpensearchClient {search_documents(&self.inner, args).await}- /// Gets all results for a given document id- #[tracing::instrument(skip(self))]- pub async fn get_document_by_id(&self, document_id: &str) -> Result<Vec<DocumentIndex>> {- get_document::get_document_by_id(&self.inner, document_id).await- }-/// Deletes a document from the opensearch document index#[tracing::instrument(skip(self))]pub async fn delete_document(&self, document_id: &str) -> Result<()> {diff --git a/rust/cloud-storage/opensearch_client/src/error.rs b/rust/cloud-storage/opensearch_client/src/error.rsindex d16c168084..d585d50a85 100644--- a/rust/cloud-storage/opensearch_client/src/error.rs+++ b/rust/cloud-storage/opensearch_client/src/error.rs@@ -1,7 +1,4 @@-use opensearch::{- Error,- http::{StatusCode, response::Response},-};+use opensearch::{Error, http::response::Response};#[derive(thiserror::Error, Debug, serde::Serialize, PartialEq)]#[serde(tag = "type")]@@ -62,12 +59,13 @@ pub trait ResponseExt {impl ResponseExt for Response {async fn map_client_error(self) -> Result<Response, OpensearchClientError> {- match self.status_code() {- StatusCode::OK | StatusCode::CREATED | StatusCode::ACCEPTED => Ok(self),- _ => Err(OpensearchClientError::NetworkError {+ if self.status_code().is_success() {+ Ok(self)+ } else {+ Err(OpensearchClientError::NetworkError {status_code: self.status_code().as_u16(),message: self.text().await.unwrap_or_default(),- }),+ })}}}diff --git a/rust/cloud-storage/opensearch_client/src/get_document.rs b/rust/cloud-storage/opensearch_client/src/get_document.rsdeleted file mode 100644index ac5a4d0e0d..0000000000--- a/rust/cloud-storage/opensearch_client/src/get_document.rs+++ /dev/null@@ -1,67 +0,0 @@-use crate::{- DOCUMENTS_INDEX, Result, error::OpensearchClientError, search::documents::DocumentIndex,-};--#[derive(Debug, serde::Serialize, serde::Deserialize)]-pub struct DocumentHit {- _source: DocumentIndex,-}--#[derive(Debug, serde::Serialize, serde::Deserialize)]-pub struct DocumentHits {- hits: Vec<DocumentHit>,-}--#[derive(Debug, serde::Serialize, serde::Deserialize)]-pub struct SearchDocumentResponse {- pub hits: DocumentHits,-}--/// Given a specific document id, this function will return the document if it exists-pub(crate) async fn get_document_by_id(- client: &opensearch::OpenSearch,- document_id: &str,-) -> Result<Vec<DocumentIndex>> {- let response = client- .search(opensearch::SearchParts::Index(&[DOCUMENTS_INDEX]))- .body(serde_json::json!({- "query": {- "bool": {- "must": [- {- "term": {- "document_id": document_id- }- }- ]- }- },- }))- .send()- .await- .map_err(|err| OpensearchClientError::DeserializationFailed {- details: err.to_string(),- method: Some("get_document_by_id".to_string()),- })?;-- let result = response- .json::<SearchDocumentResponse>()- .await- .map_err(|e| OpensearchClientError::DeserializationFailed {- details: e.to_string(),- method: Some("search_documents".to_string()),- })?;-- if result.hits.hits.is_empty() {- return Ok(vec![]);- }-- println!("{result:?}");-- Ok(result- .hits- .hits- .into_iter()- .map(|hit| hit._source)- .collect())-}diff --git a/rust/cloud-storage/opensearch_client/src/lib.rs b/rust/cloud-storage/opensearch_client/src/lib.rsindex 4b9948b7e7..8037695a34 100644--- a/rust/cloud-storage/opensearch_client/src/lib.rs+++ b/rust/cloud-storage/opensearch_client/src/lib.rs@@ -1,7 +1,7 @@pub mod date_format;pub mod delete;pub mod error;-pub mod get_document;+pub mod name;pub mod search;pub mod search_on;pub mod unified;@@ -28,12 +28,6 @@ use opensearch::{indices::{IndicesCreateParts, IndicesExistsParts},};-pub static DOCUMENTS_INDEX: &str = "documents";-pub static CHAT_INDEX: &str = "chats";-pub static EMAIL_INDEX: &str = "emails";-pub static CHANNEL_INDEX: &str = "channels";-pub static PROJECT_INDEX: &str = "projects";-#[derive(Clone, Debug)]pub struct OpensearchClient {/// The opensearch client used to interact with opensearch apidiff --git a/rust/cloud-storage/opensearch_client/src/name.rs b/rust/cloud-storage/opensearch_client/src/name.rsnew file mode 100644index 0000000000..ab8b950411--- /dev/null+++ b/rust/cloud-storage/opensearch_client/src/name.rs@@ -0,0 +1,12 @@+use crate::{+ OpensearchClient, Result,+ upsert::name::{UpsertEntityNameArgs, upsert_entity_name},+};++impl OpensearchClient {+ /// Upserts an entity name into the opensearch index+ #[tracing::instrument(skip(self), err)]+ pub async fn upsert_entity_name(&self, args: &UpsertEntityNameArgs) -> Result<()> {+ upsert_entity_name(&self.inner, args).await+ }+}diff --git a/rust/cloud-storage/opensearch_client/src/search/builder.rs b/rust/cloud-storage/opensearch_client/src/search/builder.rsindex ba7a82ba83..78612cb333 100644--- a/rust/cloud-storage/opensearch_client/src/search/builder.rs+++ b/rust/cloud-storage/opensearch_client/src/search/builder.rs@@ -46,9 +46,6 @@ macro_rules! delegate_methods {pub trait SearchQueryConfig {/// Key for item idconst ID_KEY: &'static str = "entity_id";- /// Index name- #[allow(dead_code)]- const INDEX: &'static str;/// Key for user idconst USER_ID_KEY: &'static str;/// Key for titlediff --git a/rust/cloud-storage/opensearch_client/src/search/builder/test.rs b/rust/cloud-storage/opensearch_client/src/search/builder/test.rsindex 9724a87423..a4c62b72d8 100644--- a/rust/cloud-storage/opensearch_client/src/search/builder/test.rs+++ b/rust/cloud-storage/opensearch_client/src/search/builder/test.rs@@ -5,7 +5,6 @@ use opensearch_query_builder::ToOpenSearchJson;struct TestSearchConfig;impl SearchQueryConfig for TestSearchConfig {- const INDEX: &'static str = "test_index";const USER_ID_KEY: &'static str = "test_user_id";const TITLE_KEY: &'static str = "test_title";}diff --git a/rust/cloud-storage/opensearch_client/src/search/channels.rs b/rust/cloud-storage/opensearch_client/src/search/channels.rsindex 134adb89e0..0d054004a4 100644--- a/rust/cloud-storage/opensearch_client/src/search/channels.rs+++ b/rust/cloud-storage/opensearch_client/src/search/channels.rs@@ -1,5 +1,5 @@use crate::{- CHANNEL_INDEX, Result, delegate_methods,+ Result, delegate_methods,error::{OpensearchClientError, ResponseExt},search::{builder::{SearchQueryBuilder, SearchQueryConfig},@@ -9,6 +9,7 @@ use crate::{};use crate::SearchOn;+use models_opensearch::SearchIndex;use opensearch_query_builder::{BoolQueryBuilder, FieldSort, QueryType, ScoreWithOrderSort, SearchRequest, SortOrder, SortType,ToOpenSearchJson,@@ -52,7 +53,6 @@ pub struct ChannelMessageSearchResponse {pub(crate) struct ChannelMessageSearchConfig;impl SearchQueryConfig for ChannelMessageSearchConfig {- const INDEX: &'static str = CHANNEL_INDEX;const USER_ID_KEY: &'static str = "sender_id";const TITLE_KEY: &'static str = "channel_name";@@ -198,7 +198,9 @@ pub(crate) async fn search_channel_messages(let query_body = args.build()?;let response = client- .search(opensearch::SearchParts::Index(&[CHANNEL_INDEX]))+ .search(opensearch::SearchParts::Index(&[+ SearchIndex::Channels.as_ref()+ ])).body(query_body).send().awaitdiff --git a/rust/cloud-storage/opensearch_client/src/search/chats.rs b/rust/cloud-storage/opensearch_client/src/search/chats.rsindex 71f24048fc..ef1983339d 100644--- a/rust/cloud-storage/opensearch_client/src/search/chats.rs+++ b/rust/cloud-storage/opensearch_client/src/search/chats.rs@@ -1,5 +1,5 @@use crate::{- CHAT_INDEX, Result, delegate_methods,+ Result, delegate_methods,error::{OpensearchClientError, ResponseExt},search::{builder::{SearchQueryBuilder, SearchQueryConfig},@@ -10,6 +10,7 @@ use crate::{};use crate::SearchOn;+use models_opensearch::SearchIndex;use opensearch_query_builder::{BoolQueryBuilder, FieldSort, ScoreWithOrderSort, SearchRequest, SortOrder, SortType,ToOpenSearchJson,@@ -42,7 +43,6 @@ pub struct ChatSearchResponse {pub(crate) struct ChatSearchConfig;impl SearchQueryConfig for ChatSearchConfig {- const INDEX: &'static str = CHAT_INDEX;const USER_ID_KEY: &'static str = "user_id";const TITLE_KEY: &'static str = "title";@@ -161,7 +161,9 @@ pub(crate) async fn search_chats(let query_body = args.build()?;let response = client- .search(opensearch::SearchParts::Index(&[CHAT_INDEX]))+ .search(opensearch::SearchParts::Index(&[+ SearchIndex::Chats.as_ref()+ ])).body(query_body).send().awaitdiff --git a/rust/cloud-storage/opensearch_client/src/search/documents.rs b/rust/cloud-storage/opensearch_client/src/search/documents.rsindex 45e5aee24e..5871823b5c 100644--- a/rust/cloud-storage/opensearch_client/src/search/documents.rs+++ b/rust/cloud-storage/opensearch_client/src/search/documents.rs@@ -1,5 +1,5 @@use crate::{- DOCUMENTS_INDEX, Result, delegate_methods,+ Result, delegate_methods,error::{OpensearchClientError, ResponseExt},search::{builder::{SearchQueryBuilder, SearchQueryConfig},@@ -9,6 +9,7 @@ use crate::{};use crate::SearchOn;+use models_opensearch::SearchIndex;use opensearch_query_builder::{BoolQueryBuilder, FieldSort, ScoreWithOrderSort, SearchRequest, SortOrder, SortType,ToOpenSearchJson,@@ -19,7 +20,6 @@ use serde_json::Value;pub(crate) struct DocumentSearchConfig;impl SearchQueryConfig for DocumentSearchConfig {- const INDEX: &'static str = DOCUMENTS_INDEX;const USER_ID_KEY: &'static str = "owner_id";const TITLE_KEY: &'static str = "document_name";@@ -144,7 +144,9 @@ pub(crate) async fn search_documents(tracing::trace!("query: {}", query_body);let response = client- .search(opensearch::SearchParts::Index(&[DOCUMENTS_INDEX]))+ .search(opensearch::SearchParts::Index(&[+ SearchIndex::Documents.as_ref()+ ])).body(query_body).send().awaitdiff --git a/rust/cloud-storage/opensearch_client/src/search/emails.rs b/rust/cloud-storage/opensearch_client/src/search/emails.rsindex f8e26f09a5..0152b3e53d 100644--- a/rust/cloud-storage/opensearch_client/src/search/emails.rs+++ b/rust/cloud-storage/opensearch_client/src/search/emails.rs@@ -1,5 +1,5 @@use crate::{- EMAIL_INDEX, Result, delegate_methods,+ Result, delegate_methods,error::{OpensearchClientError, ResponseExt},search::{builder::{SearchQueryBuilder, SearchQueryConfig},@@ -10,6 +10,7 @@ use crate::{};use crate::SearchOn;+use models_opensearch::SearchIndex;use opensearch_query_builder::{BoolQueryBuilder, FieldSort, QueryType, ScoreWithOrderSort, SearchRequest, SortOrder, SortType,ToOpenSearchJson,@@ -21,7 +22,6 @@ use serde_json::Value;pub(crate) struct EmailSearchConfig;impl SearchQueryConfig for EmailSearchConfig {- const INDEX: &'static str = EMAIL_INDEX;const USER_ID_KEY: &'static str = "user_id";const TITLE_KEY: &'static str = "subject";@@ -249,7 +249,9 @@ pub(crate) async fn search_emails(let query_body = args.build()?;let response = client- .search(opensearch::SearchParts::Index(&[EMAIL_INDEX]))+ .search(opensearch::SearchParts::Index(&[+ SearchIndex::Emails.as_ref()+ ])).body(query_body).send().awaitdiff --git a/rust/cloud-storage/opensearch_client/src/search/model.rs b/rust/cloud-storage/opensearch_client/src/search/model.rsindex e3b1838cb0..da7c920d6c 100644--- a/rust/cloud-storage/opensearch_client/src/search/model.rs+++ b/rust/cloud-storage/opensearch_client/src/search/model.rs@@ -2,16 +2,6 @@ use std::{collections::HashMap, fmt::Display};use crate::search::query::Keys;-#[derive(Debug, Clone, Hash, Eq, PartialEq, strum::Display, strum::EnumString, strum::AsRefStr)]-#[strum(serialize_all = "lowercase")]-pub enum SearchIndex {- Channels,- Chats,- Documents,- Emails,- Projects,-}-/// macro open/close tags for highlight matches#[derive(Debug, PartialEq)]pub(crate) enum MacroEm {diff --git a/rust/cloud-storage/opensearch_client/src/search/projects.rs b/rust/cloud-storage/opensearch_client/src/search/projects.rsindex 480b67b8a4..54ce9e8e75 100644--- a/rust/cloud-storage/opensearch_client/src/search/projects.rs+++ b/rust/cloud-storage/opensearch_client/src/search/projects.rs@@ -1,5 +1,5 @@use crate::{- PROJECT_INDEX, Result, delegate_methods,+ Result, delegate_methods,error::{OpensearchClientError, ResponseExt},search::{builder::{SearchQueryBuilder, SearchQueryConfig},@@ -9,6 +9,7 @@ use crate::{};use crate::SearchOn;+use models_opensearch::SearchIndex;use opensearch_query_builder::{BoolQueryBuilder, HighlightField, SearchRequest, ToOpenSearchJson};use serde::{Deserialize, Serialize};use serde_json::Value;@@ -17,7 +18,6 @@ use serde_json::Value;pub(crate) struct ProjectSearchConfig;impl SearchQueryConfig for ProjectSearchConfig {- const INDEX: &'static str = PROJECT_INDEX;const USER_ID_KEY: &'static str = "user_id";const TITLE_KEY: &'static str = "project_name";@@ -142,7 +142,9 @@ pub(crate) async fn search_projects(let query_body = args.build()?;let response = client- .search(opensearch::SearchParts::Index(&[PROJECT_INDEX]))+ .search(opensearch::SearchParts::Index(&[+ SearchIndex::Projects.as_ref()+ ])).body(query_body).send().awaitdiff --git a/rust/cloud-storage/opensearch_client/src/search/unified.rs b/rust/cloud-storage/opensearch_client/src/search/unified.rsindex 9fd6387a42..987967e97e 100644--- a/rust/cloud-storage/opensearch_client/src/search/unified.rs+++ b/rust/cloud-storage/opensearch_client/src/search/unified.rs@@ -1,7 +1,7 @@use std::collections::HashSet;use crate::{- CHANNEL_INDEX, CHAT_INDEX, DOCUMENTS_INDEX, EMAIL_INDEX, PROJECT_INDEX, Result,+ Result,error::{OpensearchClientError, ResponseExt},search::{builder::SearchQueryConfig,@@ -19,7 +19,7 @@ use crate::{emails::{EmailIndex, EmailQueryBuilder, EmailSearchArgs, EmailSearchConfig, EmailSearchResponse,},- model::{DefaultSearchResponse, Hit, MacroEm, SearchIndex, parse_highlight_hit},+ model::{DefaultSearchResponse, Hit, MacroEm, parse_highlight_hit},projects::{ProjectIndex, ProjectQueryBuilder, ProjectSearchArgs, ProjectSearchConfig,ProjectSearchResponse,@@ -29,6 +29,7 @@ use crate::{};use crate::SearchOn;+use models_opensearch::{SearchEntityType, SearchIndex};use opensearch_query_builder::*;#[derive(Debug, Default, Clone)]@@ -42,7 +43,7 @@ pub struct UnifiedSearchArgs {pub collapse: bool,pub disable_recency: bool,/// The indices to search over- pub search_indices: HashSet<SearchIndex>,+ pub search_indices: HashSet<SearchEntityType>,/// The document search argspub document_search_args: UnifiedDocumentSearchArgs,/// The email search args. If None, we do not search emails@@ -394,55 +395,55 @@ fn build_unified_search_request(args: &UnifiedSearchArgs) -> Result<SearchRequeslet mut title_keys = vec![];for index in &args.search_indices {match index {- SearchIndex::Channels => title_keys.push(ChannelMessageSearchConfig::TITLE_KEY),- SearchIndex::Chats => title_keys.push(ChatSearchConfig::TITLE_KEY),- SearchIndex::Documents => title_keys.push(DocumentSearchConfig::TITLE_KEY),- SearchIndex::Emails => title_keys.push(EmailSearchConfig::TITLE_KEY),- SearchIndex::Projects => title_keys.push(ProjectSearchConfig::TITLE_KEY),+ SearchEntityType::Channels => title_keys.push(ChannelMessageSearchConfig::TITLE_KEY),+ SearchEntityType::Chats => title_keys.push(ChatSearchConfig::TITLE_KEY),+ SearchEntityType::Documents => title_keys.push(DocumentSearchConfig::TITLE_KEY),+ SearchEntityType::Emails => title_keys.push(EmailSearchConfig::TITLE_KEY),+ SearchEntityType::Projects => title_keys.push(ProjectSearchConfig::TITLE_KEY),}}let mut bool_query = BoolQueryBuilder::new();bool_query.minimum_should_match(1);- if args.search_indices.contains(&SearchIndex::Documents) {+ if args.search_indices.contains(&SearchEntityType::Documents) {let document_search_args: DocumentSearchArgs = args.clone().into();let document_query_builder: DocumentQueryBuilder = document_search_args.into();let mut document_bool_query = document_query_builder.build_bool_query()?;- document_bool_query.must(QueryType::term("_index", DOCUMENTS_INDEX));+ document_bool_query.must(QueryType::term("_index", SearchIndex::Documents.as_ref()));bool_query.should(document_bool_query.build().into());}- if args.search_indices.contains(&SearchIndex::Emails) {+ if args.search_indices.contains(&SearchEntityType::Emails) {let email_search_args: EmailSearchArgs = args.clone().into();let email_query_builder: EmailQueryBuilder = email_search_args.into();let mut email_bool_query = email_query_builder.build_bool_query()?;- email_bool_query.must(QueryType::term("_index", EMAIL_INDEX));+ email_bool_query.must(QueryType::term("_index", SearchIndex::Emails.as_ref()));bool_query.should(email_bool_query.build().into());}- if args.search_indices.contains(&SearchIndex::Channels) {+ if args.search_indices.contains(&SearchEntityType::Channels) {let channel_message_search_args: ChannelMessageSearchArgs = args.clone().into();let channel_message_query_builder: ChannelMessageQueryBuilder =channel_message_search_args.into();let mut channel_message_bool_query = channel_message_query_builder.build_bool_query()?;- channel_message_bool_query.must(QueryType::term("_index", CHANNEL_INDEX));+ channel_message_bool_query.must(QueryType::term("_index", SearchIndex::Channels.as_ref()));bool_query.should(channel_message_bool_query.build().into());}- if args.search_indices.contains(&SearchIndex::Chats) {+ if args.search_indices.contains(&SearchEntityType::Chats) {let chat_search_args: ChatSearchArgs = args.clone().into();let chat_query_builder: ChatQueryBuilder = chat_search_args.into();let mut chat_bool_query = chat_query_builder.build_bool_query()?;- chat_bool_query.must(QueryType::term("_index", CHAT_INDEX));+ chat_bool_query.must(QueryType::term("_index", SearchIndex::Chats.as_ref()));bool_query.should(chat_bool_query.build().into());}- if args.search_indices.contains(&SearchIndex::Projects) {+ if args.search_indices.contains(&SearchEntityType::Projects) {let project_search_args: ProjectSearchArgs = args.clone().into();let project_query_builder: ProjectQueryBuilder = project_search_args.into();let mut project_bool_query = project_query_builder.build_bool_query()?;- project_bool_query.must(QueryType::term("_index", PROJECT_INDEX));+ project_bool_query.must(QueryType::term("_index", SearchIndex::Projects.as_ref()));bool_query.should(project_bool_query.build().into());}diff --git a/rust/cloud-storage/opensearch_client/src/search/unified/test.rs b/rust/cloud-storage/opensearch_client/src/search/unified/test.rsindex 9d69bedbb1..ac8a5d84ba 100644--- a/rust/cloud-storage/opensearch_client/src/search/unified/test.rs+++ b/rust/cloud-storage/opensearch_client/src/search/unified/test.rs@@ -402,11 +402,11 @@ fn test_deserialization() -> anyhow::Result<()> {fn test_build_unified_search_request_content() -> anyhow::Result<()> {let unified_search_args = UnifiedSearchArgs {search_indices: vec![- SearchIndex::Documents,- SearchIndex::Emails,- SearchIndex::Projects,- SearchIndex::Channels,- SearchIndex::Chats,+ SearchEntityType::Documents,+ SearchEntityType::Emails,+ SearchEntityType::Projects,+ SearchEntityType::Channels,+ SearchEntityType::Chats,].into_iter().collect(),@@ -798,11 +798,11 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {fn test_build_unified_search_request_name() -> anyhow::Result<()> {let unified_search_args = UnifiedSearchArgs {search_indices: vec![- SearchIndex::Documents,- SearchIndex::Emails,- SearchIndex::Projects,- SearchIndex::Channels,- SearchIndex::Chats,+ SearchEntityType::Documents,+ SearchEntityType::Emails,+ SearchEntityType::Projects,+ SearchEntityType::Channels,+ SearchEntityType::Chats,].into_iter().collect(),@@ -1234,11 +1234,11 @@ fn test_build_unified_search_request_name() -> anyhow::Result<()> {fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {let unified_search_args = UnifiedSearchArgs {search_indices: vec![- SearchIndex::Documents,- SearchIndex::Emails,- SearchIndex::Projects,- SearchIndex::Channels,- SearchIndex::Chats,+ SearchEntityType::Documents,+ SearchEntityType::Emails,+ SearchEntityType::Projects,+ SearchEntityType::Channels,+ SearchEntityType::Chats,].into_iter().collect(),@@ -1887,7 +1887,7 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {#[test]fn test_build_unified_search_request_single_index() -> anyhow::Result<()> {let unified_search_args = UnifiedSearchArgs {- search_indices: vec![SearchIndex::Documents].into_iter().collect(),+ search_indices: vec![SearchEntityType::Documents].into_iter().collect(),terms: vec!["test".to_string()],user_id: "user".to_string(),page: 1,diff --git a/rust/cloud-storage/opensearch_client/src/upsert/channel_message.rs b/rust/cloud-storage/opensearch_client/src/upsert/channel_message.rsindex 06b7ba4267..ca9d4e0d8f 100644--- a/rust/cloud-storage/opensearch_client/src/upsert/channel_message.rs+++ b/rust/cloud-storage/opensearch_client/src/upsert/channel_message.rs@@ -1,4 +1,6 @@-use crate::{CHANNEL_INDEX, Result, date_format::EpochSeconds, error::OpensearchClientError};+use models_opensearch::SearchIndex;++use crate::{Result, date_format::EpochSeconds, error::OpensearchClientError};/// The arguments for upserting a channel message into the opensearch index#[derive(Debug, serde::Serialize)]@@ -25,7 +27,10 @@ pub(crate) async fn upsert_channel_message(let id = format!("{}:{}", args.channel_id, args.message_id);let response = client- .index(opensearch::IndexParts::IndexId(CHANNEL_INDEX, &id))+ .index(opensearch::IndexParts::IndexId(+ SearchIndex::Channels.as_ref(),+ &id,+ )).body(args).send().awaitdiff --git a/rust/cloud-storage/opensearch_client/src/upsert/chat_message.rs b/rust/cloud-storage/opensearch_client/src/upsert/chat_message.rsindex 8352691219..7fda820294 100644--- a/rust/cloud-storage/opensearch_client/src/upsert/chat_message.rs+++ b/rust/cloud-storage/opensearch_client/src/upsert/chat_message.rs@@ -1,4 +1,6 @@-use crate::{CHAT_INDEX, Result, date_format::EpochSeconds, error::OpensearchClientError};+use models_opensearch::SearchIndex;++use crate::{Result, date_format::EpochSeconds, error::OpensearchClientError};/// The arguments for upserting a chat message into the opensearch index#[derive(Debug, serde::Serialize)]@@ -29,7 +31,10 @@ pub(crate) async fn upsert_chat_message() -> Result<()> {let id = format!("{}:{}", args.chat_id, args.chat_message_id);let response = client- .index(opensearch::IndexParts::IndexId(CHAT_INDEX, &id))+ .index(opensearch::IndexParts::IndexId(+ SearchIndex::Chats.as_ref(),+ &id,+ )).body(args).send().await@@ -90,7 +95,7 @@ pub(crate) async fn update_chat_metadata(});let response = client- .update_by_query(UpdateByQueryParts::Index(&[CHAT_INDEX]))+ .update_by_query(UpdateByQueryParts::Index(&[SearchIndex::Chats.as_ref()])).body(query).send().awaitdiff --git a/rust/cloud-storage/opensearch_client/src/upsert/document.rs b/rust/cloud-storage/opensearch_client/src/upsert/document.rsindex 0374f61650..9c4dbdc885 100644--- a/rust/cloud-storage/opensearch_client/src/upsert/document.rs+++ b/rust/cloud-storage/opensearch_client/src/upsert/document.rs@@ -1,4 +1,6 @@-use crate::{DOCUMENTS_INDEX, Result, date_format::EpochSeconds, error::OpensearchClientError};+use models_opensearch::SearchIndex;++use crate::{Result, date_format::EpochSeconds, error::OpensearchClientError};/// The arguments for upserting a document into the opensearch index#[derive(Debug, serde::Serialize)]@@ -100,7 +102,9 @@ async fn bulk_upsert_single_chunk(}let response = client- .bulk(opensearch::BulkParts::Index(DOCUMENTS_INDEX))+ .bulk(opensearch::BulkParts::Index(+ SearchIndex::Documents.as_ref(),+ )).body(bulk_body).refresh(opensearch::params::Refresh::WaitFor) // Ensure consistency.send()@@ -226,7 +230,10 @@ pub(crate) async fn upsert_document() -> Result<()> {let id = format!("{}:{}", args.document_id, args.node_id);let response = client- .index(opensearch::IndexParts::IndexId(DOCUMENTS_INDEX, &id))+ .index(opensearch::IndexParts::IndexId(+ SearchIndex::Documents.as_ref(),+ &id,+ )).body(args).send().await@@ -285,7 +292,9 @@ pub(crate) async fn update_document_metadata(});let response = client- .update_by_query(UpdateByQueryParts::Index(&[DOCUMENTS_INDEX]))+ .update_by_query(UpdateByQueryParts::Index(+ &[SearchIndex::Documents.as_ref()],+ )).body(query).send().awaitdiff --git a/rust/cloud-storage/opensearch_client/src/upsert/email.rs b/rust/cloud-storage/opensearch_client/src/upsert/email.rsindex eb1fafae9c..1fca8a7707 100644--- a/rust/cloud-storage/opensearch_client/src/upsert/email.rs+++ b/rust/cloud-storage/opensearch_client/src/upsert/email.rs@@ -1,4 +1,6 @@-use crate::{EMAIL_INDEX, Result, date_format::EpochSeconds, error::OpensearchClientError};+use models_opensearch::SearchIndex;++use crate::{Result, date_format::EpochSeconds, error::OpensearchClientError};/// The arguments for upserting an email message into the opensearch index#[derive(Debug, serde::Serialize)]@@ -39,7 +41,10 @@ pub(crate) async fn upsert_email_message() -> Result<()> {let id = format!("{}:{}", args.thread_id, args.message_id);let response = client- .index(opensearch::IndexParts::IndexId(EMAIL_INDEX, &id))+ .index(opensearch::IndexParts::IndexId(+ SearchIndex::Emails.as_ref(),+ &id,+ )).body(args).send().awaitdiff --git a/rust/cloud-storage/opensearch_client/src/upsert/mod.rs b/rust/cloud-storage/opensearch_client/src/upsert/mod.rsindex 287e4e9120..78ab6d11f3 100644--- a/rust/cloud-storage/opensearch_client/src/upsert/mod.rs+++ b/rust/cloud-storage/opensearch_client/src/upsert/mod.rs@@ -2,4 +2,5 @@ pub mod channel_message;pub mod chat_message;pub mod document;pub mod email;+pub mod name;pub mod project;diff --git a/rust/cloud-storage/opensearch_client/src/upsert/name.rs b/rust/cloud-storage/opensearch_client/src/upsert/name.rsnew file mode 100644index 0000000000..d0a3760317--- /dev/null+++ b/rust/cloud-storage/opensearch_client/src/upsert/name.rs@@ -0,0 +1,37 @@+//! This module handles the upserting of entity names into the opensearch index++use models_opensearch::{SearchEntityType, SearchIndex};++use crate::{Result, error::ResponseExt};++/// The arguments for upserting an entity name into the opensearch index+#[derive(Debug, serde::Serialize)]+pub struct UpsertEntityNameArgs {+ /// The entity id+ pub entity_id: String,+ /// The entity name+ pub name: String,+ /// The entity type+ pub entity_type: SearchEntityType,+}++#[tracing::instrument(skip(client), err)]+pub(crate) async fn upsert_entity_name(+ client: &opensearch::OpenSearch,+ args: &UpsertEntityNameArgs,+) -> Result<()> {+ client+ .index(opensearch::IndexParts::IndexId(+ SearchIndex::Names.as_ref(),+ &args.entity_id,+ ))+ .body(args)+ .send()+ .await+ .map_client_error()+ .await?;++ tracing::trace!(id=%args.entity_id, "entity name upserted successfully");++ Ok(())+}diff --git a/rust/cloud-storage/opensearch_client/src/upsert/project.rs b/rust/cloud-storage/opensearch_client/src/upsert/project.rsindex 742fe901ff..9ab096942e 100644--- a/rust/cloud-storage/opensearch_client/src/upsert/project.rs+++ b/rust/cloud-storage/opensearch_client/src/upsert/project.rs@@ -1,4 +1,6 @@-use crate::{PROJECT_INDEX, Result, date_format::EpochSeconds, error::OpensearchClientError};+use models_opensearch::SearchIndex;++use crate::{Result, date_format::EpochSeconds, error::OpensearchClientError};/// The arguments for upserting a project into the opensearch index#[derive(Debug, serde::Serialize)]@@ -18,7 +20,7 @@ pub(crate) async fn upsert_project() -> Result<()> {let response = client.index(opensearch::IndexParts::IndexId(- PROJECT_INDEX,+ SearchIndex::Projects.as_ref(),&args.project_id,)).body(args)diff --git a/rust/cloud-storage/search_processing_service/src/process/mod.rs b/rust/cloud-storage/search_processing_service/src/process/mod.rsindex ad3354442a..ecc618dec9 100644--- a/rust/cloud-storage/search_processing_service/src/process/mod.rs+++ b/rust/cloud-storage/search_processing_service/src/process/mod.rs@@ -3,6 +3,7 @@ mod chat;pub mod context;mod document;mod email;+mod name;mod project;mod user;pub mod worker;@@ -32,8 +33,8 @@ pub async fn process_message();match search_extractor_message {- SearchQueueMessage::UpdateEntityName(_message) => {- todo!()+ SearchQueueMessage::UpdateEntityName(message) => {+ name::upsert_name(&ctx.opensearch_client, &ctx.db, &message).await?;}SearchQueueMessage::RemoveUserProfile(user_profile_id) => {tracing::trace!(user_profile_id = user_profile_id, "removing user profile");diff --git a/rust/cloud-storage/search_processing_service/src/process/name.rs b/rust/cloud-storage/search_processing_service/src/process/name.rsnew file mode 100644index 0000000000..5a1cd458ef--- /dev/null+++ b/rust/cloud-storage/search_processing_service/src/process/name.rs@@ -0,0 +1,34 @@+//! This module handles the processing of entity name messages++use opensearch_client::{OpensearchClient, upsert::name::UpsertEntityNameArgs};+use sqs_client::search::name::UpdateEntityName;++/// Handles upserting the name for an entity+#[tracing::instrument(skip(opensearch_client, db), err)]+pub async fn upsert_name(+ opensearch_client: &OpensearchClient,+ db: &sqlx::Pool<sqlx::Postgres>,+ message: &UpdateEntityName,+) -> anyhow::Result<()> {+ // Get entity name from db+ let entity_name =+ macro_db_client::entity_name::get_entity_name(db, &message.entity_id, &message.entity_type)+ .await?;++ let name = if let Some(entity_name) = entity_name {+ entity_name+ } else {+ return Ok(());+ };++ // Perform upsert+ opensearch_client+ .upsert_entity_name(&UpsertEntityNameArgs {+ entity_id: message.entity_id.to_string(),+ name,+ entity_type: message.entity_type.clone(),+ })+ .await?;++ Ok(())+}diff --git a/rust/cloud-storage/sqs_client/Cargo.toml b/rust/cloud-storage/sqs_client/Cargo.tomlindex b789edc15d..4ad2649ad6 100644--- a/rust/cloud-storage/sqs_client/Cargo.toml+++ b/rust/cloud-storage/sqs_client/Cargo.toml@@ -28,7 +28,7 @@ email = ["model", "models_email"]gmail = ["model", "uuid"]insight_context = ["model"]organization_retention = []-search = ["chrono", "model"]+search = ["chrono", "model", "models_opensearch", "uuid"]sfs_uploader = []upload_extractor = []@@ -43,3 +43,4 @@ serde_json = { workspace = true }strum = { workspace = true, features = ["derive"] }tracing = { workspace = true }uuid = { workspace = true, optional = true }+models_opensearch = { path = "../models_opensearch", optional = true }diff --git a/rust/cloud-storage/sqs_client/src/search/mod.rs b/rust/cloud-storage/sqs_client/src/search/mod.rsindex dc1b83a61b..455ab87143 100644--- a/rust/cloud-storage/sqs_client/src/search/mod.rs+++ b/rust/cloud-storage/sqs_client/src/search/mod.rs@@ -127,7 +127,7 @@ impl PrimaryId for SearchQueueMessage {SearchQueueMessage::BulkRemoveProjectMessage(message) => message.project_ids[0].clone(),SearchQueueMessage::RemoveUserProfile(message) => message.clone(),- SearchQueueMessage::UpdateEntityName(message) => message.entity_id.clone(),+ SearchQueueMessage::UpdateEntityName(message) => message.entity_id.to_string(),}}}diff --git a/rust/cloud-storage/sqs_client/src/search/name.rs b/rust/cloud-storage/sqs_client/src/search/name.rsindex 0a49cd0d7b..63d39fcaed 100644--- a/rust/cloud-storage/sqs_client/src/search/name.rs+++ b/rust/cloud-storage/sqs_client/src/search/name.rs@@ -1,20 +1,10 @@-/// Tells you the entity type that we are inserting the name for-/// These values map directly to the names of the opensearch indices-/// Projects is excluded because it handles names on its own-#[derive(serde::Serialize, serde::Deserialize, PartialEq, Eq, Debug)]-#[serde(rename_all = "lowercase")]-pub enum NameEntityType {- Channels,- Chats,- Documents,- Emails,-}+use models_opensearch::SearchEntityType;/// Update entity name message/// Sent to SPS via a queue for processing to update the names index with the new name/// of the entity#[derive(serde::Serialize, serde::Deserialize, PartialEq, Eq, Debug)]pub struct UpdateEntityName {- pub entity_id: String,- pub entity_type: NameEntityType,+ pub entity_id: uuid::Uuid,+ pub entity_type: SearchEntityType,}