Activity Feeds v3 is in beta — try it out!

Querying Activities

Activity Search & Queries

You can query & search activities. Here’s an example of how to query activities:

var response = await _feedsV3Client.QueryActivitiesAsync(
    new QueryActivitiesRequest
    {
        Limit = 10,
        Filter = new Dictionary<string, object> { ["activity_type"] = "post" }
    }
);

When searching activities, the activity.current_feed field contains information about the feed the activity belongs to. However, if an activity is posted to multiple feeds, this field will be empty. In this case, you can use the activity.feeds array to read all feed IDs the activity was posted to and fetch feeds separately if needed.

Search filter syntax emulates a MongoDB style query syntax. (It emulates it, we don’t use MongoDB, but the query syntax is nice here).

Querying activities by text

var response = await _feedsV3Client.QueryActivitiesAsync(
    new QueryActivitiesRequest
    {
        Limit = 10,
        Filter = new Dictionary<string, object> { ["activity_type"] = "post" }
    }
);

Querying activities by search data

Consider this example activity:

{
  "id": "activity-123",
  "type": "post",
  "text": "Check out our spring sale!",
  "search_data": {
    "campaign": {
      "id": "spring-sale-2025",
      "location": {
        "mall": "yorkdale",
        "city": "toronto",
        "country": "canada"
      }
    }
  }
  // ... other activity fields
}

You can search this activity using the search_data field in several ways:

var response = await _feedsV3Client.QueryActivitiesAsync(
    new QueryActivitiesRequest
    {
        Limit = 10,
        Filter = new Dictionary<string, object> { ["activity_type"] = "post" }
    }
);

Querying private activities

Private activities are by default only returned to the user that created the activity, for client side requests this happens automatically. For server side requests you can query for private activities by utilizing include_private_activities which is only available for server side requests.

// Query for activities for user `john` and include private activities
var response = await _feedsV3Client.QueryActivitiesAsync(
    new QueryActivitiesRequest
    {
        IncludePrivateActivities = true,
        Filter = new Dictionary<string, object> { ["user_id"] = "john" }
    }
);

If you are doing a pure server side integration you can set the user_id in the request to have it behave like a client side request. Private activities owned by the user will be returned, private activities for other users will not be returned.

Activities Queryable Built-In Fields

nametypedescriptionsupported operationsexample
idstring or list of stringsThe ID of the activity$in, $eq{ id: { $in: [ 'abc', 'xyz' ] } }
activity_typestring or list of stringsThe type of the activity$in, $eq{ activity_type: { $in: [ 'abc', 'xyz' ] } }
user_idstring or list of stringsThe ID of the user who created the activity$in, $eq{ user_id: { $in: [ 'abc', 'xyz' ] } }
textstringThe text content of the activity$eq, $q, $autocomplete{ text: { $q: 'popularity' } }
search_dataobjectThe extra metadata for search indexing$contains, $path_exists{ search_data: { $contains: { 'category': 'sports', 'status': 'active' } } }
interest_tagslist of stringsTags for user interests$eq, $contains{ interest_tags: { $in: [ 'sports', 'music' ] } }
filter_tagslist of stringsTags for filtering$eq, $contains{ filter_tags: { $in: [ 'categoryA', 'categoryB' ] } }
created_atstring, must be formatted as an RFC3339 timestampThe time the activity was created$eq, $gt, $lt, $gte, $lte{ created_at: { $gte: '2023-12-04T09:30:20.45Z' } }
popularitynumberThe popularity score of the activity$eq, $ne, $gt, $lt, $gte, $lte{ popularity: { $gte: 70 } }
nearobjectIndicates the GEO point to search nearby activities$eq{ near: { $eq: { lat: 40.0, lng: -74.0, distance: 200 } } }
within_boundsobjectIndicates the GEO bounds to search for activities within$eq{ within_bounds: { $eq: { ne_lat: 40.0, ne_lng: -115.0, sw_lat: 32.0, sw_lng: -125.0 } } }
hiddenbooltrue if an activity was hidden by the user. Hidden activities are excluded unless specified with filter$eq{ hidden: { $eq: true }

The filter syntax also supports $or and $and:

// Get all the activities where filter tags contain both "green" and "orange"
var filter = = new
{
  and = new[]
  {
    new { filter_tags = new[] { "green" } },
    new { filter_tags = new[] { "orange" } }
  }
}

Be sure to reach out to support if you need additional query activity capabilities.

Activities sort options

Fields:

  • created_at
  • popularity

Direction: 1 or -1

© Getstream.io, Inc. All Rights Reserved.