Search code examples
getstream-io

Using custom fields in the aggregation query


It is ok to use custom variables in the aggregation for the feed?

When I push my activity I push the following

$data = [
    'actor' => '1',
    'verb' => "$verb",
    'object' => "$objectType:$objectId",
    'target' => "$targetObjectType:$targetObjectId",
    'time' => "$time",
    'foreign_id' => "$foreignId",
     // Custom field
    'object_type' => $objectType
];

It mentions when editing the aggregation feed:

The following variables are
available to you: verb, time, object, target, id, actor.

The reason I want a custom variable is that I want to aggregate by VERB TARGET and OBJECT(TYPE). So that I can show things such as 10 points were added to your item of id 1. If we use the id as well such as object=point:1 then we can't use this in the aggregation since it will be different id for each point hence never aggregate.

I just tried using a custom variable in the aggregation and it seems to be available and works. Is anything wrong in doing that?


Solution

  • Yes, you can use custom variables in your aggregation format. There is nothing wrong with doing so. In fact it's a great solution which gives you a lot of control over the aggregation. We should clarify that more clearly in the interface.