Skip to content

Commit 428233a

Browse files
committed
removed fallback synthetic source block loader being used
1 parent 381a884 commit 428233a

File tree

3 files changed

+38
-66
lines changed

3 files changed

+38
-66
lines changed

modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/extras/MatchOnlyTextFieldMapper.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -680,16 +680,18 @@ protected void parseCreateField(DocumentParserContext context) throws IOExceptio
680680

681681
// match_only_text isn't stored, so if synthetic source needs to be supported, we must do something about it
682682
if (needsToSupportSyntheticSource()) {
683-
// if the delegate can't support synthetic source for the given value, then store a copy of said value so
684-
// that synthetic source can load it
685-
if (fieldType().textFieldType.canUseSyntheticSourceDelegateForSyntheticSource(value.string()) == false) {
686-
final String fieldName = fieldType().syntheticSourceFallbackFieldName();
687-
if (storedFieldInBinaryFormat) {
688-
final var bytesRef = new BytesRef(utfBytes.bytes(), utfBytes.offset(), utfBytes.length());
689-
context.doc().add(new StoredField(fieldName, bytesRef));
690-
} else {
691-
context.doc().add(new StoredField(fieldName, value.string()));
692-
}
683+
// check if we can use the delegate
684+
if (fieldType().textFieldType.canUseSyntheticSourceDelegateForSyntheticSource(value.string())) {
685+
return;
686+
}
687+
688+
// if not, then store this field explicitly so that synthetic source can load it
689+
final String fieldName = fieldType().syntheticSourceFallbackFieldName();
690+
if (storedFieldInBinaryFormat) {
691+
final var bytesRef = new BytesRef(utfBytes.bytes(), utfBytes.offset(), utfBytes.length());
692+
context.doc().add(new StoredField(fieldName, bytesRef));
693+
} else {
694+
context.doc().add(new StoredField(fieldName, value.string()));
693695
}
694696
}
695697
}

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/mapping/20_synthetic_source.yml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,28 @@ synthetic_source text with ignored multi-field and multiple values in the same d
160160
match_phrase:
161161
foo: this value is
162162

163-
- match: { "hits.total.value": 1 }
164-
- match: { hits.hits.0._source.foo.0: "This value is short" }
165-
- match: { hits.hits.0._source.foo.1: "This value is too long and will be ignored" }
163+
- match: { hits.total.value: 1 }
164+
- match: { hits.hits.0._source.foo.0: "This value is too long and will be ignored" }
165+
- match: { hits.hits.0._source.foo.1: "This value is short" }
166+
167+
# flip around the two values, now short first followed by a long one
168+
- do:
169+
index:
170+
index: synthetic_source_test
171+
id: "1"
172+
refresh: true
173+
body:
174+
foo: [ "a short potato", "a very looooooooooooooong potato" ]
175+
176+
- do:
177+
search:
178+
index: synthetic_source_test
179+
body:
180+
query:
181+
match_phrase:
182+
foo: potato
183+
184+
- match: { hits.total.value: 1 }
185+
# the order is flipped because the keyword field loader is added after the parent field loader
186+
- match: { hits.hits.0._source.foo.0: "a very looooooooooooooong potato" }
187+
- match: { hits.hits.0._source.foo.1: "a short potato" }

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

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
7676
import org.elasticsearch.xcontent.ToXContent;
7777
import org.elasticsearch.xcontent.XContentBuilder;
78-
import org.elasticsearch.xcontent.XContentParser;
7978

8079
import java.io.IOException;
8180
import java.util.ArrayList;
@@ -1008,9 +1007,8 @@ public boolean canUseSyntheticSourceDelegateForQuerying() {
10081007
*/
10091008
public boolean canUseSyntheticSourceDelegateForSyntheticSource(final String value) {
10101009
if (syntheticSourceDelegate.isPresent()) {
1011-
KeywordFieldMapper.KeywordFieldType kwdFieldType = syntheticSourceDelegate.get();
10121010
// if the keyword field is going to be ignored, then we can't rely on it for synthetic source
1013-
return kwdFieldType.isIgnored(value) == false;
1011+
return syntheticSourceDelegate.get().isIgnored(value) == false;
10141012
}
10151013
return false;
10161014
}
@@ -1064,60 +1062,10 @@ protected String delegatingTo() {
10641062
return new BlockStoredFieldsReader.BytesFromStringsBlockLoader(name());
10651063
}
10661064

1067-
// _ignored_source field will contain entries for this field if it is not stored
1068-
// and there is no syntheticSourceDelegate.
1069-
// See #syntheticSourceSupport().
1070-
// But if a text field is a multi field it won't have an entry in _ignored_source.
1071-
// The parent might, but we don't have enough context here to figure this out.
1072-
// So we bail.
1073-
if (isSyntheticSourceEnabled && syntheticSourceDelegate.isEmpty() && parentField == null) {
1074-
return fallbackSyntheticSourceBlockLoader(blContext);
1075-
}
1076-
10771065
SourceValueFetcher fetcher = SourceValueFetcher.toString(blContext.sourcePaths(name()));
10781066
return new BlockSourceReader.BytesRefsBlockLoader(fetcher, blockReaderDisiLookup(blContext));
10791067
}
10801068

1081-
FallbackSyntheticSourceBlockLoader fallbackSyntheticSourceBlockLoader(BlockLoaderContext blContext) {
1082-
var reader = new FallbackSyntheticSourceBlockLoader.SingleValueReader<BytesRef>(null) {
1083-
@Override
1084-
public void convertValue(Object value, List<BytesRef> accumulator) {
1085-
if (value != null) {
1086-
accumulator.add(new BytesRef(value.toString()));
1087-
}
1088-
}
1089-
1090-
@Override
1091-
protected void parseNonNullValue(XContentParser parser, List<BytesRef> accumulator) throws IOException {
1092-
var text = parser.textOrNull();
1093-
1094-
if (text != null) {
1095-
accumulator.add(new BytesRef(text));
1096-
}
1097-
}
1098-
1099-
@Override
1100-
public void writeToBlock(List<BytesRef> values, BlockLoader.Builder blockBuilder) {
1101-
var bytesRefBuilder = (BlockLoader.BytesRefBuilder) blockBuilder;
1102-
1103-
for (var value : values) {
1104-
bytesRefBuilder.appendBytesRef(value);
1105-
}
1106-
}
1107-
};
1108-
1109-
return new FallbackSyntheticSourceBlockLoader(
1110-
reader,
1111-
name(),
1112-
IgnoredSourceFieldMapper.ignoredSourceFormat(blContext.indexSettings().getIndexVersionCreated())
1113-
) {
1114-
@Override
1115-
public Builder builder(BlockFactory factory, int expectedCount) {
1116-
return factory.bytesRefs(expectedCount);
1117-
}
1118-
};
1119-
}
1120-
11211069
/**
11221070
* Build an iterator of documents that have the field. This mirrors parseCreateField,
11231071
* using whatever

0 commit comments

Comments
 (0)