Elasticsearch is a NoSQL Database focused on search capabilities to act as a search engine. The Shopware implementation of Elasticsearch provides an integrated way to improve the performance of product and category searches. To use Elasticsearch for your shop take a look at our elasticsearch guide
Elasticsearch is only used in searches that are explicitly defined. This is by default set to the
ProductSuggestRoute. To use elasticsearch on your own searches make sure to add the elasticsearch aware state to your criteria.
$criteria = new \Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria();
$context = \Shopware\Core\Framework\Context::createDefaultContext();
// Enables elasticsearch for this search
To provide Elasticsearch for an entity a corresponding
ElasticsearchDefinitionneeds to be added. Currently, Shopware has such a definition for the product entity called
ProductElasticsearchDefinition. This definition defines the fields which are provided to elasticsearch and how they are aggregated.
EntitySearcherto map the entity search to the elasticsearch structure. The
IdSearchResulthydrated by the
EntitySearcherdoes and this result is used to read the found ids from the database.
ElasticsearchEntityAggregatordoes the same as the
CriteriaParserparses the criteria to an elasticsearch specific notation.
The product search has a special
ProductSearchBuilderin the core and so has the elasticsearch extension a corresponding extension for the
ProductSearchBuilder. This extension matches the queries of the core
ProductSearchBuilderto the elasticsearch notation.
ProductUpdaterlistens to the
ProductIndexerEventand triggers the
ElasticsearchIndexeron changes to a
es:index:cleanupdeletes outdated elasticsearch indexes. The parameter
-fwill skip the confirmation.
es:create:aliasrefreshes the current elasticsearch index and sets the alias to the index name without the timestamp (which will make this index the active index). This will happen automatically when a new index is published, so this command can force the alias creation for testing purposes or if something went wrong.
es:indexre-indexes all configured entities to elasticsearch.
es:resetresets all active indices and clears the queue. This command should be used only if an index is corrupted or needs to be setup completely from scratch.
es:statusreturns the status of all current elasticsearch indices.