dimaKudr
dimaKudr

Reputation: 430

Searching for a stream in EventStore

Is it possible to search for a stream not by StreamId but by some another Stream attribute? For example, if every stream has CustomerId in the Headers and I would like to search for all the streams with the particular CustomerId.

Upvotes: 6

Views: 6859

Answers (4)

andrew pate
andrew pate

Reputation: 4299

Although it is probably not the most efficient way to find something, if you do need a list of streams so you can search them or find a particular one, there is a $streams system projection, but it needs enabling first before you can use it using something like this powershell:

uri$ = http://${EventStoreIP}:${EventStoreHttpPort}/projection/${projection}/command/enable

$result = Invoke-WebRequest -Method Post -Uri $uri -UseBasicParsing -TimeoutSec 90 -Headers @{
    Authorization = Get-BasicAuthCredentials
}

where $projection is '$streams'. Look also at the other system projections that can be enabled the same way, which may provide what you need more precisely, which are documented here: https://eventstore.org/docs/projections/system-projections/

Upvotes: 0

morleyc
morleyc

Reputation: 2431

EventStore now has projections which can do what you are looking for. Please see this blog for details

http://geteventstore.com/blog/20130227/projections-6-an-indexing-use-case/

Upvotes: 2

Sebastian Good
Sebastian Good

Reputation: 6360

It's likely you're trying to use the event store incorrectly. An event store is built only for saving and reading streams of committed events for rebuilding event-sourced aggregates. Implementations provide headers for conveniently implementing infrastructure concerns, such as request/response correlation IDs, auditing, security, and the like. If you find yourself putting business attributes in there -- like a customer id -- then you may need to instead build a read model as suggested by @eulerfx.

If it's an ID you're looking for, then you should consider making CustomerID the actual event stream ID for that customer. Loading a particular customer by its ID is exactly what you'd expect an event store to do.

Upvotes: 2

eulerfx
eulerfx

Reputation: 37719

Event stores are designed to support retrieval exclusively by the key of the entity. To support retrieval by other attributes, data is indexed in an eventually consistent, de-normalized fashion specifically for each use case and in a separate place. So the event-store only stores events and to support querying of any sort indexed projections are utilized. These are sort of like persistent views in a relational database but they can be stored in a simple key-value store. Together, an event-store and a projection store constitute part of the infrastructure behind a CQRS + Event Sourcing architecture. Take a look here and the rest of that blog for more on this subject.

Upvotes: 9

Related Questions