Important Consideration: Custom Index Support in Strapi

Important Consideration: Custom Index Support in Strapi

Before adopting Strapi for production use, it’s essential to understand a critical limitation: Strapi does not natively support custom indexes. This has been a long-standing issue and, unfortunately, it has not yet been addressed or prioritized in their official roadmap.

This limitation may not be immediately apparent during early development, as performance typically remains acceptable with smaller datasets. However, as your application scales and the volume of data grows, you may begin to experience significant performance degradation—particularly with queries that would otherwise benefit from proper indexing.

While it is technically possible to manually create indexes directly in the database, Strapi will remove these custom indexes during schema updates or content type modifications. Developers often work around this by programmatically re-creating indexes via SQL queries after each schema change. However, this approach introduces startup delays, especially when dealing with large datasets, as index creation can be a resource-intensive operation.

In short:

  • Strapi will not preserve manually added indexes.
  • There is no official or supported mechanism to define and maintain indexes within Strapi.
  • Re-creating indexes at runtime can lead to long startup times and heavy compute costs.

Wow, I didn’t know about this, because I’m running small datasets. Would love to see an official plan to address this limitation.

Thanks

Can’t remember where I found this, but in the register cycle in for instance a Plugin, you can do something like this to add an index to a column in a contentType.

// create index column for content type
const prefix = contentType.split('::')[1].replace('.', '_');
const indexes = strapi.contentTypes[contentType].indexes || [];

// using postgres max length of index name is 64 characters so keep it short.
if (!indexes.some((i) => i.name === `${prefix}_dki`)) {
  strapi.contentTypes[contentType].indexes = [
    {
      name: `${prefix}_dki`,
      columns: ['your column name here'],
    },
  ];
}