public bool IsMigrationsInitialized() { var client = new IndexManagementClient(_db); var result = client.GetIndexAsync("automaticmigration").Result; return(result.IsSuccess); }
// make a connection to Azure Search using RedDog.Search client public void Connect() { connection = ApiConnection.Create(ServiceName, ServiceKey); managementClient = new IndexManagementClient(connection); queryClient = new IndexQueryClient(connection); connected = true; }
/// <summary> /// Initialize search. /// </summary> /// <returns></returns> public static IndexManagementClient GetSearchClient() { var connection = ApiConnection.Create(CloudConfigurationManager.GetSetting("Azure.Search.ServiceName"), CloudConfigurationManager.GetSetting("Azure.Search.ApiKey")); var indexClient = new IndexManagementClient(connection); return(indexClient); }
public EmployeesController(IOptionsSnapshot <AppConfig> appConfig, ApplicationDbContext context, ILoggerFactory loggerFactory, IHttpClientFactory httpClientFactory) { _context = context; _logger = loggerFactory.CreateLogger <EmployeesController>(); _appConfig = appConfig.Value; _httpClient = httpClientFactory.CreateClient(); _indexerClient = new check_yo_self_indexer_client.EmployeesClient(_appConfig.CheckYoSelf.IndexerBaseUri, _httpClient); _indexMgmtClient = new check_yo_self_indexer_client.IndexManagementClient(_appConfig.CheckYoSelf.IndexerBaseUri, _httpClient); }
public async Task UpdatePostAsync(Spot spot) { var client = new IndexManagementClient(connection); var result = await client.PopulateAsync("spot", new IndexOperation(IndexOperationType.Merge, "id", spot.Uid) .WithProperty("name", spot.Name) .WithProperty("description", spot.Description) .WithGeographyPoint("location", spot.Location.Longitude, spot.Location.Latitude) ); }
private static void PersistToSearch(Guid id, RegisterRestoCommand command, Coordinates coordinates) { using (var ctx = new RestoContext()) { var connection = ApiConnection.Create(CloudConfigurationManager.GetSetting("Azure.Search.ServiceName"), CloudConfigurationManager.GetSetting("Azure.Search.ApiKey")); var indexClient = new IndexManagementClient(connection); var indexName = CloudConfigurationManager.GetSetting("Azure.Search.IndexName"); var restaurant = ctx.Restaurants .Include(r => r.Accommodations.Select(a => a.Accommodation.Translations)) .FirstOrDefault(r => r.Id == id); var operation = new IndexOperation(IndexOperationType.MergeOrUpload, "id", id.ToString()) .WithProperty("name", command.Name) .WithProperty("locality", command.City) .WithProperty("budget", command.Budget) .WithProperty("rating", command.Rating) .WithProperty("street", command.Street) .WithProperty("accommodations", restaurant.Accommodations.Select(a => a.Accommodation).TryGet <Accommodation, AccommodationTranslation>("en")) .WithProperty("accommodations_fr", restaurant.Accommodations.Select(a => a.Accommodation).TryGet <Accommodation, AccommodationTranslation>("fr")) .WithProperty("accommodations_nl", restaurant.Accommodations.Select(a => a.Accommodation).TryGet <Accommodation, AccommodationTranslation>("nl")) .WithProperty("cuisine", restaurant.Cuisines.Select(a => a.Cuisine).TryGet <Cuisine, CuisineTranslation>("en")) .WithProperty("cuisine_fr", restaurant.Cuisines.Select(a => a.Cuisine).TryGet <Cuisine, CuisineTranslation>("fr")) .WithProperty("cuisine_nl", restaurant.Cuisines.Select(a => a.Cuisine).TryGet <Cuisine, CuisineTranslation>("nl")); if (coordinates != null) { operation.WithGeographyPoint("location", coordinates.Longitude, coordinates.Latitude); } var response = indexClient.PopulateAsync(indexName, operation).Result; // Error handling! if (!response.IsSuccess) { Console.WriteLine("Error: " + response.StatusCode); return; } else { var failed = response.Body.Where(r => !r.Status); foreach (var item in failed) { Console.WriteLine("Failed: {0} ({1})", item.Key, item.ErrorMessage); } } Console.WriteLine("Persisted to Search."); } }
public void AppendVersion(string schema, string version) { var client = new IndexManagementClient(_db); var result = client.PopulateAsync("automaticmigration", new IndexOperation(IndexOperationType.Upload, "Id", Guid.NewGuid().ToString()) .WithProperty("SchemaName", schema) .WithProperty("Version", version) .WithProperty("TimeOfUpdate", DateTimeOffset.Now)).Result; if (!result.IsSuccess) { throw new ApplicationException("Could not store migration in AutomaticMigration index. Error: " + result.Error.Message); } }
/// <summary> /// Initializes a new instance of the <see cref="SearchBase"/> class /// </summary> /// <param name="log">Log</param> /// <param name="serviceName">name of the search service</param> /// <param name="serviceAdminKey">key to access the search service</param> /// <param name="indexName">which index to talk to</param> /// <param name="documentHandleName">the key into the index</param> protected SearchBase(ILog log, string serviceName, string serviceAdminKey, string indexName, string documentHandleName) { this.Log = log; // check service credentials if (string.IsNullOrEmpty(serviceName) || string.IsNullOrEmpty(serviceAdminKey)) { this.Log.LogException("got bad search credentials"); } // create connection and clients and index this.Log.LogInformation("creating connection and index clients to Azure Search"); this.connection = ApiConnection.Create(serviceName, serviceAdminKey); this.managementClient = new IndexManagementClient(this.connection); this.queryClient = new IndexQueryClient(this.connection); this.indexName = indexName; this.documentHandleName = documentHandleName; }
public override void Execute(ApiConnection db) { var client = new IndexManagementClient(db); var result = client.CreateIndexAsync(new Index("plopindex") .WithStringField("Id", f => f .IsKey() .IsRetrievable()) .WithStringField("PlopField", f => f .IsSearchable() .IsRetrievable()) .WithStringField("AddedField", f => f .IsSearchable() .IsRetrievable()) .WithDateTimeField("SomeTime", f => f .IsRetrievable())).Result; if (!result.IsSuccess) { throw new ApplicationException("Could not create plopindex index: " + result.Error.Message); } }
/// <summary> /// Task is executed automatically in a transaction /// </summary> /// <param name="db"/> public override void Execute(ApiConnection db) { var client = new IndexManagementClient(db); var result = client.CreateIndexAsync(new Index("automaticmigration") .WithStringField("Id", f => f .IsKey() .IsRetrievable()) .WithStringField("SchemaName", f => f .IsSearchable() .IsRetrievable()) .WithStringField("Version", f => f .IsRetrievable()) .WithDateTimeField("TimeOfUpdate", f => f .IsRetrievable() .IsSortable())).Result; if (!result.IsSuccess) { throw new ApplicationException("Could not create automaticmigration index: " + result.Error.Message); } }
public void UntrackSchemas(IEnumerable <string> schemas) { var queryClient = new IndexQueryClient(_db); foreach (var schema in schemas) { var migrations = queryClient.SearchAsync("automaticmigration", new SearchQuery(schema) .OrderBy("TimeOfUpdate") .SearchField("SchemaName")).Result; if (!migrations.IsSuccess) { throw new ApplicationException("Error untracking schema: could not find migrations in schema " + schema + ", error: " + migrations.Error.Message); } if (migrations.Body != null) { var indexClient = new IndexManagementClient(_db); var result = indexClient.PopulateAsync("automaticmigration", migrations.Body.Records.Select(record => new IndexOperation(IndexOperationType.Delete, "Id", record.Properties["Id"].ToString())).ToArray()).Result; } } }
public ImportController(IndexManagementClient managementClient) { _managementClient = managementClient; }
public ImportController(IndexManagementClient managementClient) { _managementClient = managementClient; }
public IndexesController(IndexManagementClient managementClient) { _managementClient = managementClient; }
/// <summary> /// インデックス作成 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void button3_Click(object sender, EventArgs e) { flg = false; //前にあったデータは削除 for (int i = 0; i < fileNames.Length; i++) { var connection = ApiConnection.Create("datest01", "A53D975119F80AA1D75895645A5234BE"); var client = new IndexManagementClient(connection); client.DeleteIndexAsync("index" + i).Wait(); connection.Execute(new ApiRequest("datasources/testcontainer" + i, HttpMethod.Delete), CancellationToken.None).Wait(); connection.Execute(new ApiRequest("indexers/indexer" + i, HttpMethod.Delete), CancellationToken.None).Wait(); //データソース設定 connection.Execute(new ApiRequest("datasources", HttpMethod.Post, new { name = "source" + i, type = "azureblob", credentials = new { connectionString = "DefaultEndpointsProtocol=https;AccountName=testda01;AccountKey=Yh3sa6UyVcg8puiiBu1EYlesMSJLX45ZFwv0Ws8fxDjCin+5INxmMOBjwN0EaAN0TvFy92gjdfHHmas7lnpEzw==" }, container = new { name = "testcontainer" + i } }), CancellationToken.None).Wait(); if (fileNames[i].Contains(".csv")) { //インデックス作成 connection.Execute(new ApiRequest("indexes", HttpMethod.Post, new { name = "index" + i, fields = new List <F> { new F { name = "metadata_storage_name", type = "Edm.String", searchable = true, sortable = true, facetable = true, filterable = true }, new F { name = "Id", type = "Edm.String", searchable = true, key = true }, new F { name = "Name", type = "Edm.String", searchable = true, }, new F { name = "Age", type = "Edm.String", searchable = true, } } }), CancellationToken.None).Wait(); //インデクサ設定(ヘッダーのみ) connection.Execute(new ApiRequest("indexers", HttpMethod.Post, new { name = "indexer" + i, dataSourceName = "source" + i, targetIndexName = "index" + i, parameters = new { configuration = new { parsingMode = "delimitedText", firstLineContainsHeaders = true } } }), CancellationToken.None).Wait(); //インデクサ作成(ヘッダー以外のみ) connection.Execute(new ApiRequest("indexers", HttpMethod.Post, new { name = "indexer" + i, dataSourceName = "source" + i, targetIndexName = "index" + i, parameters = new { configuration = new { parsingMode = "delimitedText", delimitedTextHeaders = "Id,Name,Age", } } }), CancellationToken.None).Wait(); connection.Execute(new ApiRequest("indexers/indexer" + i + "/run", HttpMethod.Post), CancellationToken.None).Wait(); } else { //インデックス作成 connection.Execute(new ApiRequest("indexes", HttpMethod.Post, new { name = "index" + i, fields = new List <F> { new F { name = "metadata_storage_content_md5", type = "Edm.String", searchable = true, sortable = true, facetable = true, filterable = true, key = true }, new F { name = "metadata_storage_name", type = "Edm.String", searchable = true, sortable = true, facetable = true, filterable = true, }, new F { name = "content", type = "Edm.String", searchable = true, sortable = true, facetable = true, filterable = true } } }), CancellationToken.None).Wait(); //インデクサ設定 connection.Execute(new ApiRequest("indexers", HttpMethod.Post, new { name = "indexer" + i, dataSourceName = "source" + i, targetIndexName = "index" + i, }), CancellationToken.None).Wait(); connection.Execute(new ApiRequest("indexers/indexer" + i + "/run", HttpMethod.Post), CancellationToken.None).Wait(); } } await Task.Run(() => Thread.Sleep(5000)); MessageBox.Show("インデックスの設定が終了したよ"); flg = true; }
public IndexesController(IndexManagementClient managementClient) { _managementClient = managementClient; }