Typesense collections

Collections are created within the Craft CMS through a config file. Copy over src/config.php and edit to get started with your collections.


Return an array with a keyed value collections. This key contains an array of all the collections you want to add. You can find all the supported Typesense Field Types here(opens new window)

Per array item, you will create a new TypesenseCollectionIndex. Here’s a basic example on how to achieve this

Collection fields


The name is how the collection will be named in Typesense. If you’re using different indexes per environment, you would simply do this (if you’re using the default environment variable, you can change this to whatever suits in your .env file):


We need both the section and the entry type to defer the difference in our Typesense core to collect the data. Pick the section handle from within the Sections and take the entry type handle (also required when there’s only one entry type available).


These are the fields that needs to be created within the document inside of an index. To get the available types, please check the Field Types documentation. To learn more about the schema’s, you can read upon these on the pre-defined schema documentation

Default sorting field

The documents will be sorted on this field by default. As a warning, you can only use int32 / float fields to sort upon.


This function will give each entry queries by the Section variable. You need to map the fieds you need within Typesense. Make sure you’re using the correct types, which means for example to format your datestamps to unix.

Element type

Define which element from Craft CMS is used to provide the data. You can look up the documentation to map out the data


Define the query to fetch the data from within the Database. You can look at the Craft CMS documentation on how to fetch data from within PHP. You don’t have to define the ->all(), this is being handled within the plugin.