Skip to content
GitHubXDiscord

Index

The Index resource lets you manage AWS OpenSearchServerless Indexs and their configuration settings.

Create a basic OpenSearchServerless index with required properties and a common optional setting:

import AWS from "alchemy/aws/control";
const basicIndex = await AWS.OpenSearchServerless.Index("basicIndex", {
IndexName: "my-first-index",
CollectionEndpoint: "https://my-collection-endpoint.com",
Mappings: {
properties: {
title: { type: "text" },
createdAt: { type: "date" }
}
}
});

Configure an index with advanced settings such as custom analysis and replica count:

const advancedIndex = await AWS.OpenSearchServerless.Index("advancedIndex", {
IndexName: "my-advanced-index",
CollectionEndpoint: "https://my-collection-endpoint.com",
Mappings: {
properties: {
title: { type: "text" },
description: { type: "text" },
createdAt: { type: "date" }
}
},
Settings: {
number_of_replicas: 2,
analysis: {
analyzer: {
my_custom_analyzer: {
type: "custom",
tokenizer: "standard",
filter: ["lowercase"]
}
}
}
}
});

Create an index that specifies both mappings and index settings for performance tuning:

const tunedIndex = await AWS.OpenSearchServerless.Index("tunedIndex", {
IndexName: "performance-tuned-index",
CollectionEndpoint: "https://my-collection-endpoint.com",
Mappings: {
properties: {
title: { type: "text" },
content: { type: "text", index: true },
createdAt: { type: "date" }
}
},
Settings: {
number_of_shards: 3,
number_of_replicas: 1
}
});

Configure an index to adopt an existing resource if it already exists:

const adoptedIndex = await AWS.OpenSearchServerless.Index("adoptedIndex", {
IndexName: "existing-index",
CollectionEndpoint: "https://my-collection-endpoint.com",
adopt: true // This will adopt the existing index if it is found
});