A plugin for Strapi to help facilitate integration with Elasticsearch.
Via the plugin UI, you can define multiple Elasticsearch indexes and create reuseable mappings matched to Strapi content type fields. In addition, the plugin listens to Strapi events and will automatically index CMS records onto ES indexes, according to the indexes and mappings setup within the plugin.
EIMU = "Elasticsearch Index & Mapping Utility"
Author's note - I made this plugin to satisfy a few goals: learn Strapi plugin development, have a deeper understanding of Elasticsearch and help progress a large project I'm currently working on. The work originally started as a fork of Punit Sethi's plugin, however EIMU's scope is much greater and essentially the plugin has been completely re-built.
Some general screenshots
Still evolving and currently supports...
- Multiple ES indexes
- Re-useable mappings (presets) shared between indexes
- Relational fields i.e. if a record has relations, the plugin will index those records too
- Instant-indexing and scheduled-indexing (cron cycle)
- ES dynamic mapping
- Advanced ES mappings (e.g. geopoint)
- Batch Strapi lifecycle events
- Orphan scan and removal
- Export/import
This plugin may be most effective in the following contexts:
- Frequent model changes - Any project where data models change frequently (e.g. early in app development), having a need to integrate Elasticsearch early on, and making changes via UI is more appealing than via code
- Only basic ES needed - Anytime basic ES features are enough; no need for code
- Learning & exploration - A dev wants to learn ES and be gradually exposed to it
Note that this plugin only covers basic ES features and does not cover the full spectrum of Elasticsearch capabilities.
Note: An official npm release is coming soon.
For now, anyone wishing to experiment with the plugin in the current state, follow these steps:
- Working Strapi 4 instance
- Working Elasticsearch 8 instance
- Clone this repo into your Strapi plugins folder; the folder structure would be:
src/plugins/eimu/
- Within the plugin folder, install packages via
npm install
- Define env variables (see below)
- In your Strapi plugins config, add an entry for this plugin (see below)
- Build Strapi, via
strapi build
in Strapi root - Run Strapi, via
strapi develop
in Strapi root - Alternatively: For hot-reload, run Strapi with
strapi develop --watch-admin
and also runtsc -p tsconfig.server.json -w
in the plugin folder - Open Strapi and observe the plugin; you should see "EIMU" in the plugins section of the Strapi dashboard navigation
.env variables
URL example: https://localhost:9200
ELASTIC_HOST="YOUR_ES_URL"
ELASTIC_USERNAME="YOUR_ES_USERNAME"
ELASTIC_PASSWORD="YOUR_ES_PASSWORD"
config/plugins.ts
export default () => ({
'eimu': {
enabled: true,
resolve: "./src/plugins/eimu",
config: {
connection: {
host: process.env.ELASTIC_HOST,
username: process.env.ELASTIC_USERNAME,
password: process.env.ELASTIC_PASSWORD,
}
// OPTIONAL
// For not-instant indexing...
// Define cron schedule for processing of indexing tasks
cronSchedule: "* * * * *"
// Examples:
// cronSchedule: "0 1 * * *" // run daily at 1:00 AM
// cronSchedule: "* * * * *" // run every minute
}
}
})
General operation:
(in the plugin UI)
- Register some indexes
- Make some mappings within that index
(now use Strapi like normal)
- Go ahead and modify some Strapi records (in whatever way you do that) of a type that you've defined mappings for
- Observe your ES index (in whatever way you do that) and confirm the newly indexed records
Essentially, when active, the plugin listens to Strapi lifecycle events and will automatically index affected records, according to the indexes and mappings you've defined in the plugin.
- This is a React app (Strapi plugin)
- Typescript
- ES6
- Elasticsearch 8 API
- Strapi v5 support
- npm release
- Strapi Marketplace entry
- Better logging features (perhaps Logstash support)
- Support for multiple ES API versions (e.g. ES 9) - Makes sense
- Support for OpenSearch - In theory this could be supported if patterns are similar
- Support for Algolia - A wild thought; possible?
- Support for agnostic vanilla indexes (JSON) - Instead of ES, a registered index is simply rendered as static JSON, accessible via an API route. EXAMPLE USE CASE: A Strapi content type is used as taxonomy entries, that needs to be fed to a website (moreover perhaps only at build-time) and is updated bi-monthly. It doesn't need searchability, and will have a maximum of say 50 objects each with 3 string fields. Elasticsearch is completely overkill for this context, however, it's still an index-with-mappings and still needs to be dynamically updated (without involving a developer doing a code update).