Skip to main content

Search result batch size

Abstract

Configuring the search result batch size.

The maximum batch size for any search operation is 1000. This value is hardcoded and cannot currently be configured. In the following example, the .Skip() and .Take() method are not being used to limit the size of the result set. A maximum of 1000 contacts will be returned.

using Sitecore.XConnect.Collection.Model;
using System;
using System.Linq;
using Sitecore.XConnect;

namespace Documentation
{
    public class SearchCountLImit
    {
        public async void Example()
        {
            using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
            {
                try
                {
                    IAsyncQueryable<Sitecore.XConnect.Contact> queryable = client.Contacts
                        .Where(c => c.Interactions.Any(x => x.WebVisit().Browser.BrowserMajorName == "Chrome"))
                        .OrderBy(c => c.EngagementMeasures().MostRecentInteractionStartDateTime)
                        .WithExpandOptions(new Sitecore.XConnect.ContactExpandOptions()
                        {
                            Interactions = new Sitecore.XConnect.RelatedInteractionsExpandOptions()
                            {
                                Limit = 20
                            }
                        });

                    SearchResults<Sitecore.XConnect.Contact> results = await queryable.ToSearchResults();
                    var totalResults = results.Count; // SHOWS ACTUAL TOTAL, COULD BE OVER 1000

                    var contacts = await results.Results.Select(x => x.Item).ToList(); // LIMITED TO 1000
                }
                catch (XdbExecutionException ex)
                {
                    // Handle exception
                }
            }
        }
    }
}