Work with search

Version: 9.3

The xConnect Client API allows you to search contacts (via client.Contacts) and interactions (via client.Interactions). Interaction search is also known as behavioral search. It is not possible to query events and facets directly - you must structure your query around contacts or interactions as demonstrated in the following table:

Query Requirement

Query

Get all London addresses

Get all contacts where the AddressList facet contains a London address

Get all page visits that occurred yesterday

Get all interactions that occurred yesterday and contain events of type PageViewEvent

Get all ‘download’ events from the last week

Get all interactions that occurred in the last week and contain DownloadEvent events

Indexing

Important

Indexing is performed by a dedicated search indexer, not by the processing server. This is a significant change from version 8.2 and earlier versions.

For more information about indexing and the architecture of xConnect search, see:

Refer to the xConnect Client API overview for a complete list of synchronous and asynchronous extension methods.

xConnect does not use Sitecore.ContentSearch

xConnect search does not rely on Sitecore.ContentSearch. xConnect search and Content Search are separate frameworks with separate APIs and indexing mechanisms. For more information, refer to the search and indexing overview.

Search is case-insensitive

Search is case-insensitive by default to make it easier to locate results. This is set at Solr schema level.

Support for joins depends on the search provider

Solr supports joins between contacts and interactions. Azure Search does not currently support joins.

The following example demonstrates how to search for any contact that has downloaded a particular media item. The query uses a join.

RequestResponse
var mediaItemId = Guid.Parse("bf34c300-0c0a-4aab-9055-97854f17d134");

var query = client.Contacts.Where(c => c.Interactions.Any(x => x.Events.OfType<DownloadEvent>().Any(d => d.ItemId == mediaItemId)));

var results = await query.GetBatchEnumerator(10);

If you are using a search provider that does not support joins, you must use the contact’s InteractionsCache facet:

RequestResponse
var mediaItemId = Guid.Parse("bf34c300-0c0a-4aab-9055-97854f17d134");

var query = client.Contacts.Where(c => c.InteractionsCache().InteractionCaches.Any(x => x.DownloadEventItemIds.Any(f => f == mediaItemId)));

var results = await query.GetBatchEnumerator(10);

Do you have some feedback for us?

If you have suggestions for improving this article,