forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Prototype an approach to field aliases that creates a new top-level mapper type. #1
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6340245
Prototype an approach to field aliases that creates a new top-level m…
jtibshirani bdd8b21
Allow for aliases when fetching stored fields.
jtibshirani b25f395
Allow for aliases when requesting suggestions.
jtibshirani 1bee5db
Make sure to return the right field name in FieldTypeLookup#simpleMat…
jtibshirani 75c78a0
In the internal highlighter APIs, use the field type as opposed to th…
jtibshirani 24ff1d8
Allow for aliases when requesting highlights.
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 hidden or 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
121 changes: 121 additions & 0 deletions
121
server/src/main/java/org/elasticsearch/index/mapper/FieldAliasMapper.java
This file contains hidden or 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,121 @@ | ||
| /* | ||
| * Licensed to Elasticsearch under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.index.mapper; | ||
|
|
||
| import org.elasticsearch.common.xcontent.XContentBuilder; | ||
| import org.elasticsearch.common.xcontent.support.XContentMapValues; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collections; | ||
| import java.util.Iterator; | ||
| import java.util.Map; | ||
|
|
||
| public class FieldAliasMapper extends Mapper { | ||
| public static final String CONTENT_TYPE = "alias"; | ||
|
|
||
| public static class Names { | ||
| public static final String PATH = "path"; | ||
| } | ||
|
|
||
| private final String name; | ||
| private final String path; | ||
|
|
||
| public FieldAliasMapper(String simpleName, | ||
| String name, | ||
| String path) { | ||
| super(simpleName); | ||
| this.name = name; | ||
| this.path = path; | ||
| } | ||
|
|
||
| @Override | ||
| public String name() { | ||
| return name; | ||
| } | ||
|
|
||
| public String path() { | ||
| return path; | ||
| } | ||
|
|
||
| @Override | ||
| public Mapper merge(Mapper mergeWith) { | ||
| if (!(mergeWith instanceof FieldAliasMapper)) { | ||
| throw new IllegalArgumentException("Cannot merge a field alias [" + name() + | ||
| "] with a mapping that is not an alias [" + mergeWith.name() + "]."); | ||
| } | ||
| return mergeWith; | ||
| } | ||
|
|
||
| @Override | ||
| public Mapper updateFieldType(Map<String, MappedFieldType> fullNameToFieldType) { | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public Iterator<Mapper> iterator() { | ||
| return Collections.emptyIterator(); | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| return builder.startObject(simpleName()) | ||
| .field("type", CONTENT_TYPE) | ||
| .field(Names.PATH, path) | ||
| .endObject(); | ||
| } | ||
|
|
||
| public static class TypeParser implements Mapper.TypeParser { | ||
| @Override | ||
| public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext parserContext) | ||
| throws MapperParsingException { | ||
| FieldAliasMapper.Builder builder = new FieldAliasMapper.Builder(name); | ||
| Object pathField = node.remove(Names.PATH); | ||
| String path = XContentMapValues.nodeStringValue(pathField, null); | ||
| if (path == null) { | ||
| throw new IllegalArgumentException("The [path] property must be specified."); | ||
| } | ||
| return builder.path(path); | ||
| } | ||
| } | ||
|
|
||
| public static class Builder extends Mapper.Builder<FieldAliasMapper.Builder, FieldAliasMapper> { | ||
| private String name; | ||
| private String path; | ||
|
|
||
| protected Builder(String name) { | ||
| super(name); | ||
| this.name = name; | ||
| } | ||
|
|
||
| public String name() { | ||
| return this.name; | ||
| } | ||
|
|
||
| public Builder path(String path) { | ||
| this.path = path; | ||
| return this; | ||
| } | ||
|
|
||
| public FieldAliasMapper build(BuilderContext context) { | ||
| String fullName = context.path().pathAsText(name); | ||
| return new FieldAliasMapper(name, fullName, path); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Im going to guess this is incomplete, but im going to guess here, that it wont be able to provide all the proper checking im performing on the path, eg:
etc.
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.
Here's where I was thinking we would check if the alias was valid: https://github.com/jtibshirani/elasticsearch/pull/1/files#diff-c35d5ab4eb379e531c33305a916faceaR403. Other validation is already performed in
MapperService/FieldTypeLookup, so there is some precedent for this.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.
@jtibshirani
Seem strange your comment says check here, and a few lines below it seems the state is updated ( is it ??) again.
Uh oh!
There was an error while loading. Please reload this page.
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.
Actually precent is really my concern, my concern is whether the entire state of mappings is complete by the stage you wish to perform your checks.
Is it possible for "updates" to happen "after" this spot, which will result in a mappings that have not all been verified ? Basically is it possible that the target of an alias, might point to one thing when 403 is executed but after that the target field is something else, and never gets checked.