Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(opensearch): create names index (#267)

Will Hutchinson2160f22c14a3
diff --git a/infra/stacks/opensearch/helpers/constants.ts b/infra/stacks/opensearch/helpers/constants.ts
index bb3b29ba7c..460fa7658c 100644
--- a/infra/stacks/opensearch/helpers/constants.ts
+++ b/infra/stacks/opensearch/helpers/constants.ts
@@ -3,6 +3,7 @@ const DOCUMENT_INDEX = 'documents';
const EMAIL_INDEX = 'emails';
const CHANNEL_INDEX = 'channels';
const PROJECT_INDEX = 'projects';
+const NAMES_INDEX = 'names';
export {
CHAT_INDEX,
@@ -10,6 +11,7 @@ export {
EMAIL_INDEX,
CHANNEL_INDEX,
PROJECT_INDEX,
+ NAMES_INDEX,
};
export const SHARD_SETTINGS =
diff --git a/infra/stacks/opensearch/helpers/scripts/create_indices.ts b/infra/stacks/opensearch/helpers/scripts/create_indices.ts
index b989dc1839..710dd71540 100644
--- a/infra/stacks/opensearch/helpers/scripts/create_indices.ts
+++ b/infra/stacks/opensearch/helpers/scripts/create_indices.ts
@@ -5,10 +5,55 @@ import {
CHAT_INDEX,
DOCUMENT_INDEX,
EMAIL_INDEX,
+ NAMES_INDEX,
PROJECT_INDEX,
SHARD_SETTINGS,
} from '../constants';
+async function createNamesIndex(opensearchClient: Client) {
+ const namesIndexExists = (
+ await opensearchClient.indices.exists({
+ index: NAMES_INDEX,
+ })
+ ).body;
+ if (!namesIndexExists) {
+ console.log(`${NAMES_INDEX} index does not exist, creating...`);
+
+ opensearchClient.indices.create({
+ index: NAMES_INDEX,
+ body: {
+ settings: {
+ ...SHARD_SETTINGS,
+ },
+ mappings: {
+ properties: {
+ // The id of the entity
+ entity_id: {
+ type: 'keyword',
+ },
+ // The name of the entity
+ name: {
+ type: 'text',
+ fields: {
+ keyword: {
+ type: 'keyword',
+ ignore_above: 128,
+ },
+ },
+ },
+ // The type of the entity
+ entity_type: {
+ type: 'keyword',
+ },
+ },
+ },
+ },
+ });
+ } else {
+ console.log(`${NAMES_INDEX} index already exists`);
+ }
+}
+
async function createChannelIndex(opensearchClient: Client) {
const channelIndexExists = (
await opensearchClient.indices.exists({
@@ -398,6 +443,7 @@ async function createIndices() {
await createEmailIndex(opensearchClient);
await createChannelIndex(opensearchClient);
await createProjectIndex(opensearchClient);
+ await createNamesIndex(opensearchClient);
console.log('done');
} catch (error) {
console.error('Error', error);