RFC: different Elastic configurations #2821
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have tried to present several different ways to configure elastic search indices. Currently, we use different JSON files for each domain. We have several problems with it:
I have these proposals:
1. Use a single Yaml file for configuration
see project-base/app/src/Resources/definition/product.yaml
Configuration is split into three main parts:
only one file per index type is used. Differences for the domains/locales/environments may be achieved with the
@something
suffix.For example, the analysis may be different for different languages, so
will be used for every domain with English locale, while
will be used only for the first domain.
The
@
suffixes are allowed in the root configurations (index, analysis, mappings) and in the individual fields in the mappings configurationSuffixes have the priority domain - locale - environment - nothing. So the setting for the domain has a higher priority over locale, and so on.
Configurations are always overwritten, so when the same configuration exists for domain and locale, only the domain will be used and nothing from the locale will be merged.
Since YAML can be easily converted to JSON, it's possible to use almost any configuration, that is in the current index definition, but the YAML allows us to use only a single (and more readable) file while allowing the differences for domains.
2. Use a PHP configuration
This idea uses PHP for configuration. This expects some kind of builder.
We can use a builder object to addFields and set analyzers, and configurations.
We can use PHP to adjust the configuration based on the domain/environment/locale.
The configuration example is available in the
project-base/app/src/Resources/definition/ProductIndexMapping.php
file.This configuration may be a little chatty and it may be harder to add uncommon configurations...
3. Use Attributes on the object
We may use class, which may be then used in the productExportRepository instead of the array.
Configuration for the elastic could be added as attributes to the fields.
That way we ensure that everything we export is properly mapped.
It's a similar concept as we use to configure Doctrine.
An example is available in
project-base/app/src/Model/Product/Elasticsearch/ElasticProduct.php
It may be harder to add an uncommon configuration (need to add a new attribute).
I have currently no idea how to implement differences for the different domains/locales.
🌐 Live Preview: