static void CreateIndex(string IndexName) { string json = File.ReadAllText("" + IndexName + ".schema"); try { Uri uri = new Uri(ServiceUri, "/indexes"); HttpResponseMessage response = AzureSearchHelper.SendSearchRequest(HttpClient, HttpMethod.Post, uri, json); response.EnsureSuccessStatusCode(); } catch (Exception ex) { Console.WriteLine("Error: {0}", ex.Message.ToString()); } }
static void ImportFromJson(string IndexName) { try { foreach (string fileName in Directory.GetFiles("", IndexName + "*.json")) { Console.WriteLine("Uploading documents from file: {0}", fileName); string json = File.ReadAllText(fileName); Uri uri = new Uri(ServiceUri, "/indexes/" + IndexName + "/docs/index"); HttpResponseMessage response = AzureSearchHelper.SendSearchRequest(HttpClient, HttpMethod.Post, uri, json); response.EnsureSuccessStatusCode(); } } catch (Exception ex) { Console.WriteLine("Error: {0}", ex.Message.ToString()); } }
private static void DeleteIndex(string IndexName) { try { try { Uri uri = new Uri(ServiceUri, "/indexes" + IndexName); HttpResponseMessage response = AzureSearchHelper.SendSearchRequest(HttpClient, HttpMethod.Delete, uri); response.EnsureSuccessStatusCode(); } catch (Exception ex) { Console.WriteLine("Error: {0}", ex.Message.ToString()); } } catch (Exception ex) { Console.WriteLine("Error deleting index: {0}\r\n", ex.Message); } }