Skip to content

Commit 63bf7d1

Browse files
committed
Revert "Feedback from MVG on fields with both keyword and text subfields"
This reverts commit aed9477.
1 parent 86e5b22 commit 63bf7d1

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,21 +1008,17 @@ protected String delegatingTo() {
10081008
}
10091009
};
10101010
}
1011-
if (isStored()) {
1012-
return new BlockStoredFieldsReader.BytesFromStringsBlockLoader(name());
1013-
}
10141011
/*
10151012
* If this is a sub-text field try and return the parent's loader. Text
10161013
* fields will always be slow to load and if the parent is exact then we
10171014
* should use that instead.
10181015
*/
1019-
// TODO: should this be removed? I think SyntheticSourceHelper already does this:
10201016
String parentField = blContext.parentField(name());
10211017
if (parentField != null) {
10221018
MappedFieldType parent = blContext.lookup().fieldType(parentField);
10231019
if (parent.typeName().equals(KeywordFieldMapper.CONTENT_TYPE)) {
10241020
KeywordFieldMapper.KeywordFieldType kwd = (KeywordFieldMapper.KeywordFieldType) parent;
1025-
if (kwd.hasDocValues() || kwd.isStored()) {
1021+
if (kwd.hasNormalizer() == false && (kwd.hasDocValues() || kwd.isStored())) {
10261022
return new BlockLoader.Delegating(kwd.blockLoader(blContext)) {
10271023
@Override
10281024
protected String delegatingTo() {
@@ -1032,6 +1028,9 @@ protected String delegatingTo() {
10321028
}
10331029
}
10341030
}
1031+
if (isStored()) {
1032+
return new BlockStoredFieldsReader.BytesFromStringsBlockLoader(name());
1033+
}
10351034

10361035
// _ignored_source field will contain entries for this field if it is not stored
10371036
// and there is no syntheticSourceDelegate.
@@ -1580,7 +1579,7 @@ public static KeywordFieldMapper getKeywordFieldMapperForSyntheticSource(Iterabl
15801579
for (Mapper sub : multiFields) {
15811580
if (sub.typeName().equals(KeywordFieldMapper.CONTENT_TYPE)) {
15821581
KeywordFieldMapper kwd = (KeywordFieldMapper) sub;
1583-
if (kwd.fieldType().hasDocValues() || kwd.fieldType().isStored()) {
1582+
if (kwd.hasNormalizer() == false && (kwd.fieldType().hasDocValues() || kwd.fieldType().isStored())) {
15841583
return kwd;
15851584
}
15861585
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ public static Object expectedValue(Map<String, Object> fieldMapping, Object valu
3939
var fields = (Map<String, Object>) fieldMapping.get("fields");
4040
if (fields != null) {
4141
var keywordMultiFieldMapping = (Map<String, Object>) fields.get("kwd");
42+
Object normalizer = fields.get("normalizer");
4243
boolean docValues = hasDocValues(keywordMultiFieldMapping, true);
4344
boolean store = keywordMultiFieldMapping.getOrDefault("store", false).equals(true);
4445
Object ignoreAbove = keywordMultiFieldMapping.get("ignore_above");
4546

4647
// See TextFieldMapper.SyntheticSourceHelper#getKeywordFieldMapperForSyntheticSource
4748
// and TextFieldMapper#canUseSyntheticSourceDelegateForLoading().
48-
boolean usingSyntheticSourceDelegate = docValues || store;
49+
boolean usingSyntheticSourceDelegate = normalizer == null && (docValues || store);
4950
boolean canUseSyntheticSourceDelegateForLoading = usingSyntheticSourceDelegate && ignoreAbove == null;
5051
if (canUseSyntheticSourceDelegateForLoading) {
5152
return KeywordFieldBlockLoaderTests.expectedValue(keywordMultiFieldMapping, value, params, testContext);

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,13 @@ private Object expected(Map<String, Object> fieldMapping, Object value, BlockLoa
118118
boolean docValues = hasDocValues(fieldMapping, true);
119119
boolean store = fieldMapping.getOrDefault("store", false).equals(true);
120120

121-
// if text sub field is stored, then always use that:
122-
var textFieldMapping = (Map<String, Object>) ((Map<String, Object>) fieldMapping.get("fields")).get("mf");
123-
if (textFieldMapping.getOrDefault("store", false).equals(true)) {
124-
return TextFieldBlockLoaderTests.expectedValue(textFieldMapping, value, params, testContext);
125-
}
126-
127-
if (docValues || store) {
121+
if (normalizer == null && (docValues || store)) {
128122
// we are using block loader of the parent field
129123
return KeywordFieldBlockLoaderTests.expectedValue(fieldMapping, value, params, testContext);
130124
}
131125

132126
// we are using block loader of the text field itself
127+
var textFieldMapping = (Map<String, Object>) ((Map<String, Object>) fieldMapping.get("fields")).get("mf");
133128
return TextFieldBlockLoaderTests.expectedValue(textFieldMapping, value, params, testContext);
134129
}
135130
}

0 commit comments

Comments
 (0)