Home > OS >  Where is ContinuationToken in Azure.Search.Documents v11
Where is ContinuationToken in Azure.Search.Documents v11

Time:02-11

In Microsoft.Azure.Search.Data v10 when calling ISearchIndexClient.Documents.SearchAsync
I got a result with a ContinuationToken property.

In Azure.Search.Documents v11 I can't find it when calling SearchClient.SearchAsync
which - as far as I have found out - is the equal call.

CodePudding user response:

I don't have a good way to explain it :) but please take a look at the code below. The code below fetches all documents from an index using continuation token:

using System;
using System.Threading.Tasks;
using Azure;
using Azure.Search.Documents;
using Azure.Search.Documents.Models;

namespace SO71052143
{
    class Program
    {
        private const string accountName = "account-name";
        private const string accountKey = "admin-key";
        private const string indexName = "index-name";

        static async Task Main(string[] args)
        {
            SearchClient client = new SearchClient(new Uri($"https://{accountName}.search.windows.net"), indexName,
                new AzureKeyCredential(accountKey));
            var results = (await client.SearchAsync<SearchDocument>("*"));
            var searchResults = results.Value.GetResultsAsync();
            string continuationToken = null;
            do
            {
                await foreach (var item in searchResults.AsPages(continuationToken))
                {
                    continuationToken = item.ContinuationToken;
                    var documents = item.Values;
                }
            } while (continuationToken != null);
        }
    }
}
  • Related