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

[7.x][ML] Refactor ML mappings and templates into JSON resources (#51… #52353

Conversation

dimitris-athanasiou
Copy link
Contributor

…765)

ML mappings and index templates have so far been created
programmatically. While this had its merits due to static typing,
there is consensus it would be clear to maintain those in json files.
In addition, we are going to adding ILM policies to these indices
and the component for a plugin to register ILM policies is
IndexTemplateRegistry. It expects the templates to be in resource
json files.

For the above reasons this commit refactors ML mappings and index
templates into json resource files that are registered via
MlIndexTemplateRegistry.

Backport of #51765

…stic#51765)

ML mappings and index templates have so far been created
programmatically. While this had its merits due to static typing,
there is consensus it would be clear to maintain those in json files.
In addition, we are going to adding ILM policies to these indices
and the component for a plugin to register ILM policies is
`IndexTemplateRegistry`. It expects the templates to be in resource
json files.

For the above reasons this commit refactors ML mappings and index
templates into json resource files that are registered via
`MlIndexTemplateRegistry`.

Backport of elastic#51765
@elasticmachine
Copy link
Collaborator

Pinging @elastic/ml-core (:ml)

return mapping(MapperService.SINGLE_MAPPING_NAME);
}

public static String mapping(String mappingType) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 7.x we need to still handle 6.x indices that have doc instead of _doc as the mapping type for the config and results index.

@@ -1290,10 +170,11 @@ public static void addDocMappingIfMissing(String alias,
IndexMetaData indexMetaData = state.metaData().index(indicesThatRequireAnUpdate[0]);
String mappingType = indexMetaData.mapping().type();

try (XContentBuilder mapping = mappingSupplier.apply(mappingType)) {
try {
String mapping = mappingSupplier.apply(mappingType);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where we pass the mapping type to the mapping supplier method.

return resultsMapping(MapperService.SINGLE_MAPPING_NAME);
}

public static String resultsMapping(String mappingType) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 7.x we need to still handle 6.x indices that have doc instead of _doc as the mapping type for the config and results index.

Copy link
Member

@davidkyle davidkyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dimitris-athanasiou dimitris-athanasiou merged commit ad56802 into elastic:7.x Feb 14, 2020
@dimitris-athanasiou dimitris-athanasiou deleted the refactor-ml-mappings-into-json-files-7x branch February 14, 2020 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants