Example #1
0
        public static Task UpsertIndexAsync(this ISearchIndexManager manager, SearchIndex indexDefinition, Action <UpsertSearchIndexOptions> configureOptions)
        {
            var options = new UpsertSearchIndexOptions();

            configureOptions(options);

            return(manager.UpsertIndexAsync(indexDefinition, options));
        }
        public async Task UpsertIndexAsync(SearchIndex indexDefinition, UpsertSearchIndexOptions options)
        {
            var baseUri = GetIndexUri(indexDefinition.Name);

            Logger.LogInformation($"Trying to upsert index with name {indexDefinition.Name} - {baseUri}");

            try
            {
                var json    = JsonConvert.SerializeObject(indexDefinition, Formatting.None);
                var content = new StringContent(json, Encoding.UTF8, MediaType.Json);
                var result  = await _client.PutAsync(baseUri, content, options.CancellationToken).ConfigureAwait(false);

                result.EnsureSuccessStatusCode();
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, $"Failed to upsert index with name {indexDefinition.Name} - {baseUri}");
                throw;
            }
        }