public void CanCreateAndListIndexes() { Run(() => { SearchServiceClient searchClient = Data.GetSearchServiceClient(); Index index1 = CreateTestIndex(); Index index2 = CreateTestIndex(); searchClient.Indexes.Create(index1); searchClient.Indexes.Create(index2); IndexListResult listResponse = searchClient.Indexes.List(); Assert.Equal(2, listResponse.Indexes.Count); IList <string> indexNames = listResponse.Indexes.Select(i => i.Name).ToList(); Assert.Contains(index1.Name, indexNames); Assert.Contains(index2.Name, indexNames); indexNames = searchClient.Indexes.ListNames(); Assert.Equal(2, indexNames.Count); Assert.Contains(index1.Name, indexNames); Assert.Contains(index2.Name, indexNames); }); }
/// <summary> /// Lists the names of all indexes available for an Azure Search /// service. Use this instead of List() when you only need index /// names. It will save bandwidth and resource utilization, especially /// if your Search Service has many indexes. /// <see href="https://docs.microsoft.com/rest/api/searchservice/List-Indexes"/> /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='searchRequestOptions'> /// Additional parameters for the operation. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <returns> /// The list of all index names for the search service. /// </returns> public static async Task <IList <string> > ListNamesAsync( this IIndexesOperations operations, SearchRequestOptions searchRequestOptions = default(SearchRequestOptions), CancellationToken cancellationToken = default(CancellationToken)) { IndexListResult indexList = await operations.ListAsync(select : "name", searchRequestOptions : searchRequestOptions, cancellationToken : cancellationToken).ConfigureAwait(false); return(GetIndexNames(indexList)); }
private static IList <string> GetIndexNames(IndexListResult indexListResult) { return(indexListResult.Indexes.Select(index => index.Name).ToList()); }