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

Add validation for field alias mappings. #31518

Merged
merged 5 commits into from
Jun 26, 2018

Conversation

jtibshirani
Copy link
Contributor

@jtibshirani jtibshirani commented Jun 21, 2018

The following restrictions are enforced on the target of an alias:

  • The target must be a concrete field, and not an object or another field alias.
  • The target field must exist at the time the alias is created.
  • If nested objects are defined, a field alias must have the same nested scope as its target.

@jtibshirani jtibshirani added the :Search Foundations/Mapping Index mappings, including merging and defining field types label Jun 21, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

Copy link
Contributor

@jpountz jpountz left a comment

Choose a reason for hiding this comment

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

I left some minor comment but it looks good to me. Thanks for tackling this!

}
}

private void validateAlias(String aliasName,
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe some docs would help on the two above methods, for instance to say that new aliases have not been added yet when validateField is called and that new fields have already been added when validateAlias is called

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

import java.util.Set;
import java.util.stream.Stream;

public class MapperMergeValidator {
Copy link
Contributor

Choose a reason for hiding this comment

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

can it be pkg-private? please also add some minimal javadocs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

String pathScope = getNestedScope(path, fullPathObjectMappers);
if (!Objects.equals(aliasScope, pathScope)) {
throw new IllegalArgumentException("Invalid [path] value [" + path + "] for field alias [" +
aliasName + "]: an alias must have the same nested scope as its target.");
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe add what we computed as the scope of the alias and the path to the error message

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@jpountz
Copy link
Contributor

jpountz commented Jun 25, 2018

@jtibshirani Could you update the description of this PR to describe what is being validated? This is important since this PR might be linked from release notes.

@jtibshirani jtibshirani force-pushed the field-alias-validation branch 2 times, most recently from 5c399fd to f4fabf5 Compare June 25, 2018 20:42
@jtibshirani jtibshirani merged commit 4890c86 into elastic:field-aliases Jun 26, 2018
@jtibshirani jtibshirani deleted the field-alias-validation branch June 26, 2018 00:01
jtibshirani added a commit that referenced this pull request Jun 26, 2018
* Perform basic validation on the target of an alias.
* Validate that an alias and its target have the same nested scope.
* Pull out some validation logic into a separate class.
* Validate the uniqueness of field alias mappings.
jtibshirani added a commit that referenced this pull request Jul 4, 2018
* Perform basic validation on the target of an alias.
* Validate that an alias and its target have the same nested scope.
* Pull out some validation logic into a separate class.
* Validate the uniqueness of field alias mappings.
jtibshirani added a commit to jtibshirani/elasticsearch that referenced this pull request Jul 16, 2018
* Perform basic validation on the target of an alias.
* Validate that an alias and its target have the same nested scope.
* Pull out some validation logic into a separate class.
* Validate the uniqueness of field alias mappings.
jtibshirani added a commit that referenced this pull request Jul 17, 2018
* Perform basic validation on the target of an alias.
* Validate that an alias and its target have the same nested scope.
* Pull out some validation logic into a separate class.
* Validate the uniqueness of field alias mappings.
jtibshirani added a commit that referenced this pull request Jul 18, 2018
* Perform basic validation on the target of an alias.
* Validate that an alias and its target have the same nested scope.
* Pull out some validation logic into a separate class.
* Validate the uniqueness of field alias mappings.
jtibshirani added a commit that referenced this pull request Jul 18, 2018
* Add basic support for field aliases in index mappings. (#31287)
* Allow for aliases when fetching stored fields. (#31411)
* Add tests around accessing field aliases in scripts. (#31417)
* Add documentation around field aliases. (#31538)
* Add validation for field alias mappings. (#31518)
* Return both concrete fields and aliases in DocumentFieldMappers#getMapper. (#31671)
* Make sure that field-level security is enforced when using field aliases. (#31807)
* Add more comprehensive tests for field aliases in queries + aggregations. (#31565)
* Remove the deprecated method DocumentFieldMappers#getFieldMapper. (#32148)
jtibshirani added a commit to jtibshirani/elasticsearch that referenced this pull request Jul 24, 2018
jtibshirani added a commit that referenced this pull request Jul 24, 2018
* Add basic support for field aliases in index mappings. (#31287)
* Allow for aliases when fetching stored fields. (#31411)
* Add tests around accessing field aliases in scripts. (#31417)
* Return both concrete fields and aliases in DocumentFieldMappers#getMapper. (#31671)
* Add documentation around field aliases. (#31538)
* Add validation for field alias mappings. (#31518)
* Make sure that field-level security is enforced when using field aliases. (#31807)
* Add more comprehensive tests for field aliases in queries + aggregations. (#31565)
* Remove the deprecated method DocumentFieldMappers#getFieldMapper. (#32148)
* Ensure that field aliases cannot be used in multi-fields. (#32219)
* Make sure that field aliases count towards the total fields limit. (#32222)
* Fix a test bug around nested aggregations and field aliases. (#32287)
* Make sure the _uid field is correctly loaded in scripts.
* Fix the failing test case FieldLevelSecurityTests#testParentChild_parentField.
* Enforce that field aliases can only be specified on indexes with a single type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Search Foundations/Mapping Index mappings, including merging and defining field types
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants