Skip to content

Commit 093ebd3

Browse files
authored
Correct the condition to use a multi field block loader in text field block loader (#126718)
1 parent 962e953 commit 093ebd3

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

server/src/main/java/org/elasticsearch/index/mapper/TextFieldMapper.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -967,12 +967,11 @@ public boolean isAggregatable() {
967967
}
968968

969969
/**
970-
* Returns true if the delegate sub-field can be used for loading and querying (ie. either isIndexed or isStored is true)
970+
* Returns true if the delegate sub-field can be used for loading.
971+
* A delegate by definition must have doc_values or be stored so most of the time it can be used for loading.
971972
*/
972973
public boolean canUseSyntheticSourceDelegateForLoading() {
973-
return syntheticSourceDelegate != null
974-
&& syntheticSourceDelegate.ignoreAbove() == Integer.MAX_VALUE
975-
&& (syntheticSourceDelegate.isIndexed() || syntheticSourceDelegate.isStored());
974+
return syntheticSourceDelegate != null && syntheticSourceDelegate.ignoreAbove() == Integer.MAX_VALUE;
976975
}
977976

978977
/**

server/src/test/java/org/elasticsearch/index/mapper/blockloader/TextFieldBlockLoaderTests.java

+14-18
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ protected Object expected(Map<String, Object> fieldMapping, Object value, TestCo
3535
var fields = (Map<String, Object>) fieldMapping.get("fields");
3636
if (fields != null) {
3737
var keywordMultiFieldMapping = (Map<String, Object>) fields.get("kwd");
38+
Object normalizer = fields.get("normalizer");
3839
boolean docValues = hasDocValues(keywordMultiFieldMapping, true);
39-
boolean index = keywordMultiFieldMapping.getOrDefault("index", true).equals(true);
4040
boolean store = keywordMultiFieldMapping.getOrDefault("store", false).equals(true);
4141
Object ignoreAbove = keywordMultiFieldMapping.get("ignore_above");
4242

43-
// See TextFieldMapper.SyntheticSourceHelper#usingSyntheticSourceDelegate
43+
// See TextFieldMapper.SyntheticSourceHelper#getKeywordFieldMapperForSyntheticSource
4444
// and TextFieldMapper#canUseSyntheticSourceDelegateForLoading().
45-
boolean usingSyntheticSourceDelegate = docValues || store;
46-
boolean canUseSyntheticSourceDelegateForLoading = usingSyntheticSourceDelegate && ignoreAbove == null && (index || store);
45+
boolean usingSyntheticSourceDelegate = normalizer == null && (docValues || store);
46+
boolean canUseSyntheticSourceDelegateForLoading = usingSyntheticSourceDelegate && ignoreAbove == null;
4747
if (canUseSyntheticSourceDelegateForLoading) {
4848
return KeywordFieldBlockLoaderTests.expectedValue(keywordMultiFieldMapping, value, params, testContext);
4949
}
5050

51-
// Even if multi-field is not eligible for loading it can still be used to produce synthetic source
51+
// Even if multi field is not eligible for loading it can still be used to produce synthetic source
5252
// and then we load from the synthetic source.
5353
// Synthetic source is actually different from keyword field block loader results
5454
// because synthetic source includes values exceeding ignore_above and block loader doesn't.
@@ -66,9 +66,7 @@ protected Object expected(Map<String, Object> fieldMapping, Object value, TestCo
6666
boolean textFieldIndexed = (boolean) fieldMapping.getOrDefault("index", true);
6767

6868
if (value == null) {
69-
if (textFieldIndexed == false
70-
&& nullValue != null
71-
&& (ignoreAbove == null || nullValue.length() <= (int) ignoreAbove)) {
69+
if (textFieldIndexed == false && nullValue != null && nullValue.length() <= (int) ignoreAbove) {
7270
return new BytesRef(nullValue);
7371
}
7472

@@ -89,7 +87,7 @@ protected Object expected(Map<String, Object> fieldMapping, Object value, TestCo
8987
var indexed = values.stream()
9088
.map(s -> s == null ? nullValue : s)
9189
.filter(Objects::nonNull)
92-
.filter(s -> ignoreAbove == null || s.length() <= (int) ignoreAbove)
90+
.filter(s -> s.length() <= (int) ignoreAbove)
9391
.map(BytesRef::new)
9492
.collect(Collectors.toList());
9593

@@ -100,22 +98,20 @@ protected Object expected(Map<String, Object> fieldMapping, Object value, TestCo
10098
}
10199

102100
// ignored values always come last
103-
List<BytesRef> ignored = ignoreAbove == null
104-
? List.of()
105-
: values.stream()
106-
.map(s -> s == null ? nullValue : s)
107-
.filter(Objects::nonNull)
108-
.filter(s -> s.length() > (int) ignoreAbove)
109-
.map(BytesRef::new)
110-
.toList();
101+
List<BytesRef> ignored = values.stream()
102+
.map(s -> s == null ? nullValue : s)
103+
.filter(Objects::nonNull)
104+
.filter(s -> s.length() > (int) ignoreAbove)
105+
.map(BytesRef::new)
106+
.toList();
111107

112108
indexed.addAll(ignored);
113109

114110
return maybeFoldList(indexed);
115111
}
116112
}
117113

118-
// Loading from _ignored_source or stored _source
114+
// Loading from stored field, _ignored_source or stored _source
119115
return valuesInSourceOrder(value);
120116
}
121117

0 commit comments

Comments
 (0)