Adding filter support to Projections

Example Events

Given some events that models planning of shipment routes for a cargo shipping company, we could have an event that looks like this:
1
{
2
"aggregateId":"723ecfce-14e9-4889-98d5-a3d0ad54912f",
3
"events":[
4
{
5
"eventId":"127b80b5-4a05-4774-b870-1c9a2e2a27a3",
6
"eventType":"RoutePlannedEvent",
7
"data":{
8
"shipmentCode": "ABC123"
9
}
10
}
11
]
12
}
Copied!

Projection definition

To make a field filterable you tell Serialized it should be a reference field. You do this by adding a setref function to the field you want to be able to filter on. In this case we want to be able to filter shipments by their shipment code:
1
{
2
"aggregated": false,
3
"projectionName": "shipments",
4
"feedName": "shipment",
5
"handlers": [
6
{
7
"eventType": "RoutePlannedEvent",
8
"functions": [
9
{
10
"function": "merge"
11
},
12
{
13
"function": "setref",
14
"targetSelector": "$.projection.shipmentCode"
15
}
16
]
17
}
18
]
19
}
Copied!

Results

You can now query your shipments Projection with a reference that will result i a match for any projection that matches shipmentCode field.
The reference query parameter is optional
/projections/single/shipments?reference=ABC123
1
{
2
"projections" : [ {
3
"projectionId" : "723ecfce-14e9-4889-98d5-a3d0ad54912f",
4
"createdAt" : 1523518145532,
5
"updatedAt" : 1523518146253,
6
"data" : {
7
"shipmentCode": "ABC123"
8
}
9
} ],
10
"totalCount" : 1
11
}
Copied!