-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Support fetching flattened subfields #70916
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
Merged
cbuescher
merged 10 commits into
elastic:master
from
cbuescher:fields-flattened-subfields
Apr 15, 2021
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f11a5e8
Support fetching flattened subfields
f556a7d
iter
e694f5a
Merge branch 'master' into fields-flattened-subfields
5110ffd
Merge branch 'master' into fields-flattened-subfields
812a3e2
iter
2880759
add yaml test
1c22ad7
add docs
4534fd1
Merge branch 'master' into fields-flattened-subfields
83c09fb
iter
6c86f2a
checkstyle
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,17 +165,19 @@ public FlattenedFieldMapper build(ContentPath contentPath) { | |
| */ | ||
| public static final class KeyedFlattenedFieldType extends StringFieldType { | ||
| private final String key; | ||
| private final String rootName; | ||
|
|
||
| public KeyedFlattenedFieldType(String name, boolean indexed, boolean hasDocValues, String key, | ||
| KeyedFlattenedFieldType(String rootName, boolean indexed, boolean hasDocValues, String key, | ||
| boolean splitQueriesOnWhitespace, Map<String, String> meta) { | ||
| super(name, indexed, false, hasDocValues, | ||
| super(rootName + KEYED_FIELD_SUFFIX, indexed, false, hasDocValues, | ||
| splitQueriesOnWhitespace ? TextSearchInfo.WHITESPACE_MATCH_ONLY : TextSearchInfo.SIMPLE_MATCH_ONLY, | ||
| meta); | ||
| this.key = key; | ||
| this.rootName = rootName; | ||
| } | ||
|
|
||
| private KeyedFlattenedFieldType(String name, String key, RootFlattenedFieldType ref) { | ||
| this(name, ref.isSearchable(), ref.hasDocValues(), key, ref.splitQueriesOnWhitespace, ref.meta()); | ||
| private KeyedFlattenedFieldType(String rootName, String key, RootFlattenedFieldType ref) { | ||
| this(rootName, ref.isSearchable(), ref.hasDocValues(), key, ref.splitQueriesOnWhitespace, ref.meta()); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -261,8 +263,11 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S | |
|
|
||
| @Override | ||
| public ValueFetcher valueFetcher(SearchExecutionContext context, String format) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just realized we should throw an error if the format is non-null, as we do for most other field types. (This is unfortunately very manual right now and easy to forget...) |
||
| // This is an internal field but it can match a field pattern so we return an empty list. | ||
| return lookup -> List.of(); | ||
| if (format != null) { | ||
| throw new IllegalArgumentException("Field [" + rootName + "." + key + "] of type [" + typeName() + | ||
| "] doesn't support formats."); | ||
| } | ||
| return SourceValueFetcher.identity(rootName + "." + key, context, format); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -426,7 +431,7 @@ private FlattenedFieldMapper(String simpleName, | |
| Builder builder) { | ||
| super(simpleName, mappedFieldType, Lucene.KEYWORD_ANALYZER, CopyTo.empty()); | ||
| this.builder = builder; | ||
| this.fieldParser = new FlattenedFieldParser(mappedFieldType.name(), keyedFieldName(), | ||
| this.fieldParser = new FlattenedFieldParser(mappedFieldType.name(), mappedFieldType.name() + KEYED_FIELD_SUFFIX, | ||
| mappedFieldType, builder.depthLimit.get(), builder.ignoreAbove.get(), builder.nullValue.get()); | ||
| } | ||
|
|
||
|
|
@@ -450,11 +455,7 @@ public RootFlattenedFieldType fieldType() { | |
|
|
||
| @Override | ||
| public KeyedFlattenedFieldType keyedFieldType(String key) { | ||
| return new KeyedFlattenedFieldType(keyedFieldName(), key, fieldType()); | ||
| } | ||
|
|
||
| public String keyedFieldName() { | ||
| return mappedFieldType.name() + KEYED_FIELD_SUFFIX; | ||
| return new KeyedFlattenedFieldType(name(), key, fieldType()); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.