Yesterday I told you, that you can select the entities which are searched by default on the Shopware administration dashboard. That was a chance find, while debugging while the search doesn’t work at all.
If you are running elastic/open search all entities which are searchable need an Indexer, a few hints how to do it, because I can’t find any documentation for it:
<service id="Shopware\Elasticsearch\Admin\Indexer\ProductAdminSearchIndexer"> <argument type="service" id="Doctrine\DBAL\Connection"/> <argument type="service" id="Shopware\Core\Framework\DataAbstractionLayer\Dbal\Common\IteratorFactory" /> <argument type="service" id="product.repository"/> <argument>%elasticsearch.indexing_batch_size%</argument> <tag name="shopware.elastic.admin-searcher-index" key="product"/> </service>
<?php declare(strict_types=1); namespace Shopware\Elasticsearch\Admin\Indexer; #[Package('system-settings')] final class ProductAdminSearchIndexer extends AbstractAdminIndexer { // [...] }
Error on the browser console
If you don’t implement this indexer and you try to use it (e.g. on the dashboard) you get an error like this:
{
"errors": [
{
"status": "500",
"code": "ELASTICSEARCH_INDEXING",
"title": "Internal Server Error",
"detail": "Following errors occurred while indexing: \n",
"meta": {
"parameters": []
}
}
]
}
Not very helpful, because the “real” error is eaten somewhere.
Looking into the log (var/log/prod-<date>.log
)
[2023-12-15T11:53:47.554940+00:00] request.CRITICAL:
Uncaught PHP Exception Shopware\Elasticsearch\Exception\ElasticsearchIndexingException:
"Following errors occurred while indexing: "
at /var/www/vendor/shopware/elasticsearch/Admin/AdminSearchRegistry.php line 17
{"exception":"[object] (Shopware\\Elasticsearch\\Exception\\ElasticsearchIndexingException(code: 0): Following errors occurred while indexing: \n at /var/www/vendor/shopware/elasticsearch/Admin/AdminSearchRegistry.php:175)"} []
Okay, a file and a line
public function getIndexer(string $name): AbstractAdminIndexer { $indexer = $this->indexer[$name] ?? null; if ($indexer) { return $indexer; } // line 175 - how unexpected. throw new ElasticsearchIndexingException([\sprintf('Indexer for name %s not found', $name)]); }
So in theory we should get this error and the indexer name, but it gets lost somewhere. So the old way
var_dump() and die() debugging
Although we know how xdebug works, there are times were “the good ol’ way” brings as faster results. And especially if I’m running on the shopware backend, I “only” disturb our customer, not the customer’s customer. So I added a var_dump($name); die();
and got an indexer name out.
Easy fix
Better fix
Implement an elastic search indexer or tell the plugin vendor to do it.