Search interactions
This topic demonstrates how to query interactions (also known as behavioral search). Each example uses the client.GetBatchEnumerator() / client.GetBatchEnumeratorSync() methods to paginate results.
Refer to the list of supported methods for xConnect search.
Search by interaction ID
Search by interaction ID is not supported. If you know the interaction ID, get the interaction from the collection database.
Search by contact ID
The following example demonstrates how to search for interactions by contact ID:
This query does not require a join.
Search by event definition ID
The following example demonstrates how to search for interactions that have at least one event with the specified defintion ID:
Some event models have fixed definition IDs - use the EventDefinitionId property rather than hard-coding a reference to the ID. For example, to search for page view events, use the PageViewEvent.EventDefinitionId property.
Search by event type
The following example demonstrates how to search by event type - for example, all events of type Goal or Outcome.
Search by event property
The following example demonstrates how to search for interactions using the properties of an event such as an outcome:
Search by interaction property
The following query returns all interactions with a ChannelId of 0565e9b0-936c-4594-8cc3-5fcace3918ed that are less than ten days old:
Search by interaction facets
The following example demonstrates how to search by interaction facets, such as IpInfo and WebVisit.
You can use the .GetFacet<TFacet> method or the an extension method such as .WebVisit() if one is available.
Results and pagination
The .GetBatchEnumerator() or .GetBatchEnumeratorSync() extension methods are the recommended way to return results from a query. See the overview of pagination for more information.
For each method, the maximum size of a single batch is hardcoded to Sitecore.XConnect.SearchExtensions.DefaultBatchSize, which is set to 1000. This value is currently not configurable.
|
Synchronous | |
|
Method |
Notes |
|
|
Recommended way of paginating results. |
|
|
Can be used with |
|
|
Can be used with |
|
Synchronous | |
|
Method |
Notes |
|
|
Recommended way of paginating results. |
|
|
Can be used with |
The following example demonstrates how to use each method to return results:
Ordering results
You can orders results by an interaction’s facets or properties. The following example demonstrates how to order interactions by StartDateTime
You cannot order by the properties of a list. For example, you cannot order interactions by the StartDateTime properties of its events.
Expand options
Use the .WithExpandOptions() method to specify which interaction facets and contact facets should be returned with each interaction. These expand options are identical to the ones that you use when retrieving a interaction by ID. If you do not specify any expand options, no facets will be returned.
The following example demonstrates how to return the WebVisit with each interaction, as well as the PersonalInformation contact facet if it is available.
The related contact’s Interactions property will always be null - you can only expand contact facets when performing an interaction search.
Count interactions
The following example demonstrates how to return a count of matching interactions. This method only returns the count, no results are sent over the wire.