-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Fix match_only_text for keyword multi-fields with ignore_above #131314
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ | |
| import org.elasticsearch.index.mapper.BlockStoredFieldsReader; | ||
| import org.elasticsearch.index.mapper.DocumentParserContext; | ||
| import org.elasticsearch.index.mapper.FieldMapper; | ||
| import org.elasticsearch.index.mapper.KeywordFieldMapper; | ||
| import org.elasticsearch.index.mapper.MappedFieldType; | ||
| import org.elasticsearch.index.mapper.MapperBuilderContext; | ||
| import org.elasticsearch.index.mapper.SourceValueFetcher; | ||
|
|
@@ -66,6 +67,7 @@ | |
| import java.io.IOException; | ||
| import java.io.UncheckedIOException; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
@@ -252,6 +254,10 @@ private IOFunction<LeafReaderContext, CheckedIntFunction<List<Object>, IOExcepti | |
| String parentField = searchExecutionContext.parentPath(name()); | ||
| var parent = searchExecutionContext.lookup().fieldType(parentField); | ||
| if (parent.isStored()) { | ||
| if (parent instanceof KeywordFieldMapper.KeywordFieldType keywordParent | ||
| && keywordParent.ignoreAbove() != Integer.MAX_VALUE) { | ||
| return storedFieldFetcher(parentField, keywordParent.originalName()); | ||
| } | ||
| return storedFieldFetcher(parentField); | ||
| } else if (parent.hasDocValues()) { | ||
| var ifd = searchExecutionContext.getForField(parent, MappedFieldType.FielddataOperation.SEARCH); | ||
|
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. It seems like there can be a similar problem here because doc values won't include ignored values? Not sure if that matters though. 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. Shoot you're right. If the keyword field is I'll work on a follow-up PR to address this. |
||
|
|
@@ -265,7 +271,11 @@ private IOFunction<LeafReaderContext, CheckedIntFunction<List<Object>, IOExcepti | |
| if (kwd != null) { | ||
| var fieldType = kwd.fieldType(); | ||
| if (fieldType.isStored()) { | ||
| return storedFieldFetcher(fieldType.name()); | ||
| if (fieldType.ignoreAbove() != Integer.MAX_VALUE) { | ||
| return storedFieldFetcher(fieldType.name(), fieldType.originalName()); | ||
| } else { | ||
| return storedFieldFetcher(fieldType.name()); | ||
| } | ||
| } else if (fieldType.hasDocValues()) { | ||
| var ifd = searchExecutionContext.getForField(fieldType, MappedFieldType.FielddataOperation.SEARCH); | ||
| return docValuesFieldFetcher(ifd); | ||
|
|
@@ -312,13 +322,17 @@ private static IOFunction<LeafReaderContext, CheckedIntFunction<List<Object>, IO | |
| }; | ||
| } | ||
|
|
||
| private static IOFunction<LeafReaderContext, CheckedIntFunction<List<Object>, IOException>> storedFieldFetcher(String name) { | ||
| var loader = StoredFieldLoader.create(false, Set.of(name)); | ||
| private static IOFunction<LeafReaderContext, CheckedIntFunction<List<Object>, IOException>> storedFieldFetcher(String... names) { | ||
| var loader = StoredFieldLoader.create(false, Set.of(names)); | ||
| return context -> { | ||
| var leafLoader = loader.getLoader(context, null); | ||
| return docId -> { | ||
| leafLoader.advanceTo(docId); | ||
| return leafLoader.storedFields().get(name); | ||
| var storedFields = leafLoader.storedFields(); | ||
| if (names.length == 1) { | ||
| return storedFields.get(names[0]); | ||
| } | ||
| return Arrays.stream(names).map(storedFields::get).filter(Objects::nonNull).flatMap(List::stream).toList(); | ||
|
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. Nit: streams are not very efficient, it's better to avoid them for code that runs per document. |
||
| }; | ||
| }; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.