HomeDev GuideRecipesAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Aggregate Optimizely Graph results

Retrieve aggregated value counts for fields in Content Graph queries to power faceted navigation and filters

👍

Early access preview

This content is an early access preview and may change before general availability. Use the thumbs up or down at the end of this article to share feedback and help shape the final release.

Use .Facet() to get value counts for one or more fields alongside query results. Facets power category navigation, "filter by author" panels, and other UI patterns that require aggregated counts.

Get facet counts

var result = await client
    .QueryContent<BlogPostPage>()
    .Facet(x => x.Author!)
    .Facet(x => x.ViewCount!)
    .GetAsContentAsync();

Read the counts back from the result:

var authorFacet = result.Facets?.GetFacet(x => x.Author);
var viewCountFacet = result.Facets?.GetFacet(x => x.ViewCount);

Each facet entry contains a value and its count.

Use facets with full-text search

Facet counts reflect the current search results, not the full content set:

var result = await client
    .QueryContent<BlogPostPage>()
    .SearchFor("api")
    .UsingFullText()
    .Facet(x => x.ViewCount)
    .GetAsContentAsync();

Filter within facets

Pass filters to apply a value filter while keeping the full facet list. This is essential for faceted navigation — it lets users refine or change their selection without losing the other options:

var result = await client
    .QueryContent<BlogPostPage>()
    .Facet(x => x.Author, filters: ["John Developer"])
    .GetAsContentAsync();

The result set is filtered to posts by "John Developer", but the facet still shows counts for all authors so the user can switch.

Multi-select faceting

Allow users to select multiple values within a single facet using OR logic. Between multiple facets, selections are combined using AND logic. Pass an empty string ("") as a placeholder for facets with no active selection:

var result = await client
    .QueryContent<BlogPostPage>()
    .Facet(x => x.BlogCategory!, filters: [""])
    .Facet(x => x.Author!, filters: ["John Developer"])
    .GetAsContentAsync();

var categoryFacet = result.Facets?.GetFacet(x => x.BlogCategory);
var authorFacet = result.Facets?.GetFacet(x => x.Author);