Making projections searchable
This page describes how to make projections searchable in Serialized.Projections can be made searchable by specifying in the definition which fields Serialized should index.
Defining a searchable single projection
To enable searching for a projection, you need to create a projection definition of type single
and specify
indexedFields
. Dot separator can be used, e.g. customer.address.streetName
. Using our SDKs there is typed support
for creating such a definition, but you can also create the definition manually using the API.
In the following example, the projected fields trackingNumber
and sku
are added to the projection index.
var definition = singleProjection("orders-by-id") .feed("order") .withIndexedFields(List.of("trackingNumber", "sku")) .addHandler(newHandler("OrderPlaced") .addFunction(Functions.merge().build()) .build()) .build()projectionClient.createDefinition(definition);
Searching indexed projections
To search for a tracking number or a SKU, simply list the single projections using the query parameter search
and then
a search string or use our SDK methods like this:
var request = ProjectionQueries.search("orders-by-id", string("123")) .build(OrderProjection.class);OrderProjection projection = projectionClient.query(request).data();
Advanced search strings
Advanced operators can be used in the search string.
Operator | Description |
---|---|
+ | specifies AND operation: token1+token2 |
| | specifies OR operation: token1 | token2 |
- | negates a single token: -token0 |
" | creates phrases of terms: "term1 term2 ..." |
* | at the end of terms specifies prefix query: term* |
~N | at the end of terms specifies fuzzy query: term~1 |
~N | at the end of phrases specifies near query: "term1 term2"~5 |
( & ) | specifies precedence: token1 + (token2 | token3) |