ABC9
6. Juni 2022 um 17:42
1
[titleEn]: <>(Index entities to elasticsearch)
[hash]: <>(article:how_to_index_es)
Once you have implemented an entity in the system that has several thousand records in the database, it makes sense to create compatibility with Elasticsearch.
This requires the `shopware/elasticsearch` bundle. If this is not available in your project, you can simply add it via `composer require shopware/elasticsearch`.
## Register the entity
To synchronize an entity to Elasticsearch the class `\Shopware\Elasticsearch\Framework\AbstractElasticsearchDefinition` is used.
The following shows how to implement such a synchronization for products.
```
<?php declare(strict_types=1);
namespace Shopware\Elasticsearch\Product;
use Shopware\Core\Content\Product\ProductDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
use Shopware\Elasticsearch\Framework\AbstractElasticsearchDefinition;
use Shopware\Elasticsearch\Framework\Indexing\EntityMapper;
This file has been truncated. show original
In diesem Beispiel werden zwar die Felder indexiert, aber suchen kann man nach denen ja nicht ohne weiteres: platform/2021-02-16-elasticsearch-refactoring.md at d6c853ca3b6b167d61d70e6329f4fcface5c5245 · shopware/platform · GitHub
Hier steht, dass man eigene Felder zu „fulltext“ oder „fulltextboosted“ hinzufügen soll. Warum sollte man nicht die „buildTermQuery“ erweitern, um z.B. ein eigenes Feld zu durchsuchen?