Example #1
0
        public static Task <SearchIndex> GetIndexAsync(this ISearchIndexManager manager, string indexName, Action <GetSearchIndexOptions> configureOptions)
        {
            var options = new GetSearchIndexOptions();

            configureOptions(options);

            return(manager.GetIndexAsync(indexName, options));
        }
        public async Task <SearchIndex> GetIndexAsync(string indexName, GetSearchIndexOptions options)
        {
            var baseUri = GetIndexUri(indexName);

            Logger.LogInformation($"Trying to get index with name {indexName} - {baseUri}");

            try
            {
                var result = await _client.GetAsync(baseUri, options.CancellationToken).ConfigureAwait(false);

                result.EnsureSuccessStatusCode();

                var json = JObject.Parse(await result.Content.ReadAsStringAsync().ConfigureAwait(false));
                return(json["indexDef"].ToObject <SearchIndex>());
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, $"Failed to get index with name {indexName} - {baseUri}");
                throw;
            }
        }