diff --git a/sdk/search/azure-search/src/samples/java/com/azure/search/CreateIndexExample.java b/sdk/search/azure-search/src/samples/java/com/azure/search/CreateIndexExample.java index 7681183b0a616..d8bc42687985f 100644 --- a/sdk/search/azure-search/src/samples/java/com/azure/search/CreateIndexExample.java +++ b/sdk/search/azure-search/src/samples/java/com/azure/search/CreateIndexExample.java @@ -17,7 +17,7 @@ public class CreateIndexExample { */ private static final String ENDPOINT = Configuration.getGlobalConfiguration().get("AZURE_COGNITIVE_SEARCH_ENDPOINT"); private static final String ADMIN_KEY = Configuration.getGlobalConfiguration().get("AZURE_COGNITIVE_SEARCH_API_KEY"); - + private static final String INDEX_NAME = "good-food"; public static void main(String[] args) { SearchApiKeyCredential searchApiKeyCredential = new SearchApiKeyCredential(ADMIN_KEY); @@ -28,7 +28,7 @@ public static void main(String[] args) { .buildClient(); Index newIndex = new Index() - .setName("good-food") + .setName(INDEX_NAME) .setFields( Arrays.asList(new Field() .setName("Name") @@ -37,7 +37,10 @@ public static void main(String[] args) { new Field() .setName("Cuisine") .setType(DataType.EDM_STRING))); - + // Create index. client.createIndex(newIndex); + + // Cleanup index resource. + client.deleteIndex(INDEX_NAME); } } diff --git a/sdk/search/azure-search/src/samples/java/com/azure/search/CreateSkillsetExample.java b/sdk/search/azure-search/src/samples/java/com/azure/search/CreateSkillsetExample.java index a93c002787cfe..53d5dfa8ac261 100644 --- a/sdk/search/azure-search/src/samples/java/com/azure/search/CreateSkillsetExample.java +++ b/sdk/search/azure-search/src/samples/java/com/azure/search/CreateSkillsetExample.java @@ -24,6 +24,8 @@ public class CreateSkillsetExample { */ private static final String ENDPOINT = Configuration.getGlobalConfiguration().get("AZURE_COGNITIVE_SEARCH_ENDPOINT"); private static final String ADMIN_KEY = Configuration.getGlobalConfiguration().get("AZURE_COGNITIVE_SEARCH_ADMIN_KEY"); + private static final String OCR_SKILLSET_NAME = "ocr-skillset"; + private static final String CUSTOME_SKILLSET_NAME = "custom-skillset"; public static void main(String[] args) { SearchServiceClient searchServiceClient = new SearchServiceClientBuilder() @@ -33,6 +35,7 @@ public static void main(String[] args) { createOcrSkillset(searchServiceClient); createCustomSkillset(searchServiceClient); + cleanupSkillset(searchServiceClient); } private static void createOcrSkillset(SearchServiceClient searchServiceClient) { @@ -66,7 +69,7 @@ private static void createOcrSkillset(SearchServiceClient searchServiceClient) { ); Skillset skillset = new Skillset() - .setName("ocr-skillset") + .setName(OCR_SKILLSET_NAME) .setDescription("Extracts text (plain and structured) from image.") .setSkills(skills); @@ -107,7 +110,7 @@ private static void createCustomSkillset(SearchServiceClient searchServiceClient .setDescription("A WebApiSkill that can be used to call a custom web api function"); Skillset skillset = new Skillset() - .setName("custom-skillset") + .setName(CUSTOME_SKILLSET_NAME) .setDescription("Skillset for testing custom skillsets") .setSkills(Collections.singletonList(webApiSkill)); @@ -119,4 +122,9 @@ private static void createCustomSkillset(SearchServiceClient searchServiceClient System.out.println(String.format("Name: %s", createdSkillset.getName())); System.out.println(String.format("ETag: %s", createdSkillset.getETag())); } + + private static void cleanupSkillset(SearchServiceClient searchServiceClient) { + searchServiceClient.deleteSkillset(OCR_SKILLSET_NAME); + searchServiceClient.deleteSkillset(CUSTOME_SKILLSET_NAME); + } } diff --git a/sdk/search/azure-search/src/samples/java/com/azure/search/LifecycleSetupExample.java b/sdk/search/azure-search/src/samples/java/com/azure/search/LifecycleSetupExample.java index fcb1369573e20..a632f6a8424c1 100644 --- a/sdk/search/azure-search/src/samples/java/com/azure/search/LifecycleSetupExample.java +++ b/sdk/search/azure-search/src/samples/java/com/azure/search/LifecycleSetupExample.java @@ -44,15 +44,14 @@ public class LifecycleSetupExample { private static final String COSMOS_CONNECTION_STRING = "AccountEndpoint=https://hotels-docbb.documents.azure.com:443/;AccountKey=4UPsNZyFAjgZ1tzHPGZaxS09XcwLrIawbXBWk6IixcxJoSePTcjBn0mi53XiKWu8MaUgowUhIovOv7kjksqAug==;Database=SampleData"; private static final String COSMOS_COLLECTION_NAME = "hotels"; - private static final String INDEX_NAME = "hotels-sample-index"; - private static final String DATASOURCE_NAME = "hotels-sample-datasource"; - private static final String SKILLSET_NAME = "hotels-sample-skillset"; - private static final String INDEXER_NAME = "hotels-sample-indexer"; + private static final String INDEX_NAME = "hotels-sample-index1"; + private static final String DATASOURCE_NAME = "hotels-sample-datasource1"; + private static final String SKILLSET_NAME = "hotels-sample-skillset1"; + private static final String INDEXER_NAME = "hotels-sample-indexer1"; private static final String SUGGESTER_NAME = "sg"; public static void main(String[] args) { SearchServiceClient client = createServiceClient(); - // Create a data source for a Cosmos DB database DataSource dataSource = createCosmosDataSource(client); System.out.println("Created DataSource " + dataSource.getName()); @@ -72,6 +71,10 @@ public static void main(String[] args) { // Update indexer schedule updateIndexerSchedule(client, indexer); System.out.println("Updated Indexer Schedule " + indexer.getName()); + + // Clean up resources. + client.deleteIndex(INDEX_NAME); + client.deleteIndexer(INDEXER_NAME); } private static SearchServiceClient createServiceClient() { diff --git a/sdk/search/azure-search/src/samples/java/com/azure/search/SynonymMapsCreateExample.java b/sdk/search/azure-search/src/samples/java/com/azure/search/SynonymMapsCreateExample.java index 95c420a364906..ad591e64a731b 100644 --- a/sdk/search/azure-search/src/samples/java/com/azure/search/SynonymMapsCreateExample.java +++ b/sdk/search/azure-search/src/samples/java/com/azure/search/SynonymMapsCreateExample.java @@ -40,6 +40,9 @@ public static void main(String[] args) { assignSynonymMapToIndex(synonymMapName); System.out.println("Complete....\n"); + + // Clean up resources + serviceClient.deleteSynonymMap(synonymMapName); } private static void createSynonymMap(SearchServiceClient serviceClient, String synonymMapName) {