OpenSearch Service examples using SDK for Kotlin - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

OpenSearch Service examples using SDK for Kotlin

The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for Kotlin with OpenSearch Service.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.

Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.

Topics

Actions

The following code example shows how to use CreateDomain.

SDK for Kotlin
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

suspend fun createNewDomain(domainNameVal: String?) { val clusterConfigOb = ClusterConfig { dedicatedMasterEnabled = true dedicatedMasterCount = 3 dedicatedMasterType = OpenSearchPartitionInstanceType.fromValue("t2.small.search") instanceType = OpenSearchPartitionInstanceType.fromValue("t2.small.search") instanceCount = 5 } val ebsOptionsOb = EbsOptions { ebsEnabled = true volumeSize = 10 volumeType = VolumeType.Gp2 } val encryptionOptionsOb = NodeToNodeEncryptionOptions { enabled = true } val request = CreateDomainRequest { domainName = domainNameVal engineVersion = "OpenSearch_1.0" clusterConfig = clusterConfigOb ebsOptions = ebsOptionsOb nodeToNodeEncryptionOptions = encryptionOptionsOb } println("Sending domain creation request...") OpenSearchClient { region = "us-east-1" }.use { searchClient -> val createResponse = searchClient.createDomain(request) println("Domain status is ${createResponse.domainStatus}") println("Domain Id is ${createResponse.domainStatus?.domainId}") } }
  • For API details, see CreateDomain in AWS SDK for Kotlin API reference.

The following code example shows how to use DeleteDomain.

SDK for Kotlin
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

suspend fun deleteSpecificDomain(domainNameVal: String) { val request = DeleteDomainRequest { domainName = domainNameVal } OpenSearchClient { region = "us-east-1" }.use { searchClient -> searchClient.deleteDomain(request) println("$domainNameVal was successfully deleted.") } }
  • For API details, see DeleteDomain in AWS SDK for Kotlin API reference.

The following code example shows how to use ListDomainNames.

SDK for Kotlin
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

suspend fun listAllDomains() { OpenSearchClient { region = "us-east-1" }.use { searchClient -> val response: ListDomainNamesResponse = searchClient.listDomainNames(ListDomainNamesRequest {}) response.domainNames?.forEach { domain -> println("Domain name is " + domain.domainName) } } }
  • For API details, see ListDomainNames in AWS SDK for Kotlin API reference.

The following code example shows how to use UpdateDomainConfig.

SDK for Kotlin
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

suspend fun updateSpecificDomain(domainNameVal: String?) { val clusterConfigOb = ClusterConfig { instanceCount = 3 } val request = UpdateDomainConfigRequest { domainName = domainNameVal clusterConfig = clusterConfigOb } println("Sending domain update request...") OpenSearchClient { region = "us-east-1" }.use { searchClient -> val updateResponse = searchClient.updateDomainConfig(request) println("Domain update response from Amazon OpenSearch Service:") println(updateResponse.toString()) } }