Here’s a simple roadmap for creating a custom indexer:
1. Create a Module
First, you need a custom Magento 2 module. This is like the foundation for your indexer. You’ll create registration.php and module.xml files to set it up.
Example:
// registration.php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    ‘KazeDigital_CustomIndexer’,
    __DIR__
);
2. Define the Indexer
Next, create an indexer.xml file to tell Magento about your new indexer—what it does, its name, and which class handles it.
Example:
<indexer id=”custom_indexer” view_id=”custom_view”>
    <class>KazeDigital\CustomIndexer\Indexer\CustomIndexer</class>
    <title>Custom Data Indexer</title>
    <description>Indexes custom data for faster website performance</description>
</indexer>
3. Create the Indexer Class
This class does the actual work of indexing your data. Think of it as the engine that processes all your information.
Example:
namespace KazeDigital\CustomIndexer\Indexer;
use Magento\Framework\Indexer\ActionInterface;
use Magento\Framework\Mview\ActionInterface as MviewActionInterface;
class CustomIndexer implements ActionInterface, MviewActionInterface
{
    public function execute($ids = null)
    {
        // Logic to reindex specific data
    }
    public function executeFull()
    {
        // Logic for full reindex
    }
}
4. Register and Test Your Indexer
Once everything is ready, run these commands to register and test your indexer:
php bin/magento setup:upgrade
php bin/magento indexer:reindex
php bin/magento indexer:status
If all goes well, you’ll see your custom indexer in the Magento admin panel, ready to make your store faster and smarter.