Skip to main content

Storage Search

The storage engine supports configurable indices that automatically index the content of storage objects written through the storageWrite API.

Only a subset of the storage object value is indexed as configured. These indices can then be searched using the query syntax.

The configured indices are populated at startup and only hold the maximum number of configured entries plus a threshold that, once surpassed, triggers the automatic eviction of the oldest entries.

Although possible, these indices are not meant to hold indexed representations of all objects in a given collection, but instead, enable complex queries to lookup cohorts of users or entities that enable different use-cases, such as offline matchmaking.

Note

The search system built on the Storage Engine is an eventually consistent system, this means that indexes are populated asynchronously which can take some milliseconds to reflect updates written to the storage objects. The search indexes fetch their results, once queried, from the Storage Engine directly so values will always be reflected from the most up to date storage object state.

Creating a new index

The indices are created and configured through the runtimes.

Index names must be unique. An index is always tied to a collection, and the top level keys of the fields of the object to index have to be specified. If no field with such key is found, the object is not indexed.

The key can be set to only index storage object with the given key, omitting this parameter leads all object keys (that match the collection and fields) to be indexed.

A maximum size is also required to be set.

As long as the names are unique, multiple indices can be created per collection, and any objects that match its configuration will be automatically indexed on storage write.

Listing from an index

The indices can be queried using the powerful query syntax that also powers the LayerG matchmaker.

To filter results by the value of any of the indexed fields, their respective keys need to be prefixed with value..

Besides the configured index fields, there are a number of queryable values that are automatically included for each index entry. These fields are:

  • update_time
  • key
  • user_id
  • version
  • create_time
  • read
  • write
  • collection

To query these fields, they do not need to be prefixed by value. in the query.

Sorting results

You can use the optional order parameter to sort storage object fields. The prefix ‘-’ before a field name indicates descending order. All specified fields must be indexed and sortable.

To sort results by the value of any of the sortable fields, their respective keys need to be prefixed with value..

RegisterStorageIndexFilter

It is possible to register a custom filtering function per index. This function will be called for each storage object that is eligible for the index, and has to return a boolean value.

If true is returned, the object will be indexed. If false is returned the object will not be indexed and will be deleted (if previously indexed).

The registered function is also applied to all eligible entries when the index is populated.