HOWTO: Enable correlation id projection with custom configuration

Hi,

Followup to my question yesterday, as I managed to figure out how to
enable correlation id projections with custom configuration. This was
basically a process of trial and error as the docs are, as pointed out
many times, in a really really bad state.

Step 1:
To enable projections add "RunProjections: System" to your EventStore
config file. This will enable support for system projections.

Step 2:
Upload your custom configuration to specify what field to use as
correlation id like this:
curl -i -X PUT --data-binary "@correlationid.json"
"http://localhost:2113/projection/%24by_correlation_id/query" -H
"accept:application/json" -u admin:changeit

correlationid.json is a JSON file which contains the config, in my case:
{"correlationIdProperty":"id"}

This refers to the "id" field in event metadata, no idea if it's
possible to use event data for this.

Step 3:
Enable the correlation id projection by doing this:
curl -i -X POST
"http://localhost:2113/projection/%24by_correlation_id/command/enable"
-H "accept:application/json" -H "Content-Length:0" -u admin:changeit

With these steps in place, if I import events that have the "id"
metadata field it would create streams that I can access with the
naming convention "$bc-someidgoeshere". All the events are links only,
so use resolveLinkTos:true to get the actual data.

This seems to have worked for me, but as above, just a case of trial
and error to figure out. Would love to see these kinds of things
actually documented, and with tutorials on the website. EventStore is
amazing, but hidden behind lack of docs on how to actually use it.

regards, Rickard

Hi Rickard,

Thanks for your feedback. Following your post, we will improve the doc here

https://eventstore.org/docs/projections/system-projections/index.html?tabs=tabid-5#by-correlation-id

and we will provide a dedicated page showing the use of the new bycorrid projection in more details.

Best

Riccardo

There is one more detail worth mentioning. I added projection setup to
the end of my EventStore Ansible script, which failed. The reason
being that you can only issue the curl commands after the whole
cluster is up and running, or else you'll get 404s for the endpoints.
So, I had to provision all servers fully first, let the cluster form,
THEN run a script that picked a server and issued the curl requests to
do the setup. That worked.

/Rickard

You can check this via gossip as well … It might be useful to add a quick endpoint for scripting purposes such as /isclusterup