Skip to content

Magento 2: Creating a custom indexer for my own module

I am new to Magento. I have a custom module in Magento 2 that has a table with data and CRUD models. I want to create an indexer for it to be able to push it to Elasticsearch.

I already created the indexer.xml and mview.xml files, as well as class inside the ModelIndexer namespace. Here it is:

namespace VendorNameFaqModelIndexer;

class Question implements MagentoFrameworkIndexerActionInterface, MagentoFrameworkMviewActionInterface
{
  public function execute($ids) {
    // ???
  }

  public function executeFull() {
    // ???
  }

  public function executeList(array $ids) {
    // ???
  }

  public function executeRow($id0 {
    // ???
  }
}

The official documentation has nothing to tell about how to get data for indexing – it only has a structure for the Indexer class.

Any suggestions, please?