Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESConfig: configurable Elasticsearch document types to allow splitting index #1296

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

haarg
Copy link
Member

@haarg haarg commented Oct 23, 2024

This adds a central module to configure all of the document types stored in Elasticsearch, allowing a config file to override values. It then adapts the rest of the code to use this module.

In the past, everything stored in Elasticsearch was stored in one index, with multiple types. Initially this was the cpan index, but later this was changed to using cpan_v1_01 with cpan being an alias. The idea was that we could have different versions of the index on the same server, and copy or switch between them. The index used would be passed around the code, acting as a single configurable value that would impact all document types. Some newer document types have been stored in separate indexes, but not all parts of the codebase accommodate this well.

Going forward, we want every document type to be in a separate index. Initially this will be one type per index. Eventually, types will go away entirely. This is required to upgrade Elasticsearch. To facilitate this, this PR adds a new module MetaCPAN::ESConfig which lists all of the document types and which index and type they are using. These values can be overridden in the config file, meaning we can switch to a different Elasticsearch instance where the documents are stored in different places just by deploying a new config file.

Everything that was previously holding a ElasticSearchX::Model index instance has been updated to instead use the ElasticSearchX::Model instance directly. The new $model->doc($doc_type) method is a replacement for $index->type($type), allowing accessing types that are in different indexes.

Everything that was previously using a copied index name with a fixed type (often like $es->search(index => $self->index->name, 'file')) is now using the new es_doc_path sub (like $es->search(es_doc_path('file'))). This seemed the easiest way to integrate this throughout the codebase.

There is a new Catalyst::Model named ESModel. This replaces both the CPAN and User models. It allows access to MetaCPAN::Model, and thus everything using ElasticSearchX::Model. The CPAN vs User split was related to the index their data was stored in, and is thus no longer relevant. The new model has less magic as well.

Fixes #1297

Centralize Elasticsearch configuration in MetaCPAN::ESConfig. Allow
overridden values from the main config file.

This module is not meant to have any behavior aside from holding the
configuration.
ESConfig knows how to find mapping data. Use it to find the mapping data
as well as index configuration.

The mapping data should be able to be moved into json files rather than
json wrapped in a module. This can happen in the future.
The analysis set in MetaCPAN::Model wasn't used for anything directly,
generate the index deployment statements. The index settings we actually
use lives in MetaCPAN::Script::Mapping::DeployStatement, so the
declarations in MetaCPAN::Model were used for nothing.
Rather than searching for modules on disk, use the explicit
configuration in ESConfig to configure MetaCPAN::Model.
PPI and thus Perl::Critic don't understand signatures, so the rule ends up prohibiting signatures as well
@haarg haarg requested review from oalders and mickeyn October 23, 2024 08:31
@haarg haarg changed the title ESConfig: configurable Elasticsearch document types ESConfig: configurable Elasticsearch document types to allow splitting index Oct 23, 2024
Allows getting a "type" object from a document name rather than needing
to specify an index and type.
Previously when trying to refresh indices, scripts would call
$self->index->refresh. This would refresh the "currently used" index.
That doesn't make any sense when splitting each type into its own index.
This was also using ElasticSearchX::Model, which we want to get rid of.

Instead, call ->indices->refresh via the Search::Elasticsearch object.
This will refresh all indices, which is fine for our purposes. In the
future, we could consider being more selective about which indices we
are refreshing, but this is no worse than the old behavior.
Rather than using the same index to find other types, find them via the
model. This means the types don't need to be in the same index.
@haarg haarg force-pushed the haarg/esconfig branch 3 times, most recently from 82860b2 to 0456203 Compare October 23, 2024 10:49
Many parts of the code treated the index as the parent of all data, so
it was the thing being passed around. That will no be true in the
future.

Instead, ESConfig can give the path (index+type) of each named document
type. Convert most places passing around index to use es_doc_path.
Replaces the CPAN and User model classes. Removes magic namespace
creation. Just returns the model object. Everything is trivially
accessible from there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Indexes with multiple types can no longer be created
1 participant