-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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 support for field aliases to 6.x. #32184
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3fd380c
Add basic support for field aliases in index mappings. (#31287)
jtibshirani 8e74f21
Allow for aliases when fetching stored fields. (#31411)
jtibshirani 01b4918
Add tests around accessing field aliases in scripts. (#31417)
jtibshirani ebc37fd
Add documentation around field aliases. (#31538)
jtibshirani 44afa78
Add validation for field alias mappings. (#31518)
jtibshirani 9f5e204
Return both concrete fields and aliases in DocumentFieldMappers#getMa…
jtibshirani 9bc098a
Make sure that field-level security is enforced when using field alia…
jtibshirani ec2b43b
Add more comprehensive tests for field aliases in queries + aggregati…
jtibshirani 7501b2c
Remove the deprecated method DocumentFieldMappers#getFieldMapper. (#3…
jtibshirani d65c8d1
Ensure that field aliases cannot be used in multi-fields. (#32219)
jtibshirani 142be2e
Make sure that field aliases count towards the total fields limit. (#…
jtibshirani 301adfd
Fix a test bug around nested aggregations and field aliases. (#32287)
jtibshirani 85d00cb
Make sure the _uid field is correctly loaded in scripts.
jtibshirani 457d204
Fix the failing test case FieldLevelSecurityTests#testParentChild_par…
jtibshirani 0fe8493
Enforce that field aliases can only be specified on indexes with a si…
jtibshirani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
[[alias]] | ||
=== Alias datatype | ||
|
||
NOTE: Field aliases can only be specified on indexes with a single mapping type. To add a field | ||
alias, the index must therefore have been created in 6.0 or later, or be an older index with | ||
the setting `index.mapping.single_type: true`. Please see <<removal-of-types>> for more information. | ||
|
||
An `alias` mapping defines an alternate name for a field in the index. | ||
The alias can be used in place of the target field in <<search, search>> requests, | ||
and selected other APIs like <<search-field-caps, field capabilities>>. | ||
|
||
[source,js] | ||
-------------------------------- | ||
PUT trips | ||
{ | ||
"mappings": { | ||
"_doc": { | ||
"properties": { | ||
"distance": { | ||
"type": "long" | ||
}, | ||
"route_length_miles": { | ||
"type": "alias", | ||
"path": "distance" // <1> | ||
}, | ||
"transit_mode": { | ||
"type": "keyword" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
GET _search | ||
{ | ||
"query": { | ||
"range" : { | ||
"route_length_miles" : { | ||
"gte" : 39 | ||
} | ||
} | ||
} | ||
} | ||
-------------------------------- | ||
// CONSOLE | ||
|
||
<1> The path to the target field. Note that this must be the full path, including any parent | ||
objects (e.g. `object1.object2.field`). | ||
|
||
Almost all components of the search request accept field aliases. In particular, aliases can be | ||
used in queries, aggregations, and sort fields, as well as when requesting `docvalue_fields`, | ||
`stored_fields`, suggestions, and highlights. Scripts also support aliases when accessing | ||
field values. Please see the section on <<unsupported-apis, unsupported APIs>> for exceptions. | ||
|
||
In some parts of the search request and when requesting field capabilities, field wildcard patterns can be | ||
provided. In these cases, the wildcard pattern will match field aliases in addition to concrete fields: | ||
|
||
[source,js] | ||
-------------------------------- | ||
GET trips/_field_caps?fields=route_*,transit_mode | ||
-------------------------------- | ||
// CONSOLE | ||
// TEST[continued] | ||
|
||
[[alias-targets]] | ||
==== Alias targets | ||
|
||
There are a few restrictions 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. | ||
|
||
Additionally, a field alias can only have one target. This means that it is not possible to use a | ||
field alias to query over multiple target fields in a single clause. | ||
|
||
[[unsupported-apis]] | ||
==== Unsupported APIs | ||
|
||
Writes to field aliases are not supported: attempting to use an alias in an index or update request | ||
will result in a failure. Likewise, aliases cannot be used as the target of `copy_to` or in multi-fields. | ||
|
||
Because alias names are not present in the document source, aliases cannot be used when performing | ||
source filtering. For example, the following request will return an empty result for `_source`: | ||
|
||
[source,js] | ||
-------------------------------- | ||
GET /_search | ||
{ | ||
"query" : { | ||
"match_all": {} | ||
}, | ||
"_source": "route_length_miles" | ||
} | ||
-------------------------------- | ||
// CONSOLE | ||
// TEST[continued] | ||
|
||
Currently only the search and field capabilities APIs will accept and resolve field aliases. | ||
Other APIs that accept field names, such as <<docs-termvectors, term vectors>>, cannot be used | ||
with field aliases. | ||
|
||
Finally, some queries, such as `terms`, `geo_shape`, and `more_like_this`, allow for fetching query | ||
information from an indexed document. Because field aliases aren't supported when fetching documents, | ||
the part of the query that specifies the lookup path cannot refer to a field by its alias. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure whether we should accept this setting, or if we should strictly enforce that the index be created in 6.0 or later. I'm concerned that there will be confusing behavior in the following case: this setting is enabled, a field alias is added, then the setting is disabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This setting can't be disabled, so it should be ok.