Skip to content

Commit e7d380b

Browse files
committed
removed fallback synthetic source block loader being used
1 parent 39e20e1 commit e7d380b

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
@@ -76,7 +76,6 @@
7676
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
7777
import org.elasticsearch.xcontent.ToXContent;
7878
import org.elasticsearch.xcontent.XContentBuilder;
79-
import org.elasticsearch.xcontent.XContentParser;
8079

8180
import java.io.IOException;
8281
import java.util.ArrayList;
@@ -1030,9 +1029,8 @@ public boolean canUseSyntheticSourceDelegateForQuerying() {
10301029
*/
10311030
public boolean canUseSyntheticSourceDelegateForSyntheticSource(final String value) {
10321031
if (syntheticSourceDelegate.isPresent()) {
1033-
KeywordFieldMapper.KeywordFieldType kwdFieldType = syntheticSourceDelegate.get();
10341032
// if the keyword field is going to be ignored, then we can't rely on it for synthetic source
1035-
return kwdFieldType.isIgnored(value) == false;
1033+
return syntheticSourceDelegate.get().isIgnored(value) == false;
10361034
}
10371035
return false;
10381036
}
@@ -1086,60 +1084,10 @@ protected String delegatingTo() {
10861084
return new BlockStoredFieldsReader.BytesFromStringsBlockLoader(name());
10871085
}
10881086

1089-
// _ignored_source field will contain entries for this field if it is not stored
1090-
// and there is no syntheticSourceDelegate.
1091-
// See #syntheticSourceSupport().
1092-
// But if a text field is a multi field it won't have an entry in _ignored_source.
1093-
// The parent might, but we don't have enough context here to figure this out.
1094-
// So we bail.
1095-
if (isSyntheticSourceEnabled && syntheticSourceDelegate.isEmpty() && parentField == null) {
1096-
return fallbackSyntheticSourceBlockLoader(blContext);
1097-
}
1098-
10991087
SourceValueFetcher fetcher = SourceValueFetcher.toString(blContext.sourcePaths(name()));
11001088
return new BlockSourceReader.BytesRefsBlockLoader(fetcher, blockReaderDisiLookup(blContext));
11011089
}
11021090

1103-
FallbackSyntheticSourceBlockLoader fallbackSyntheticSourceBlockLoader(BlockLoaderContext blContext) {
1104-
var reader = new FallbackSyntheticSourceBlockLoader.SingleValueReader<BytesRef>(null) {
1105-
@Override
1106-
public void convertValue(Object value, List<BytesRef> accumulator) {
1107-
if (value != null) {
1108-
accumulator.add(new BytesRef(value.toString()));
1109-
}
1110-
}
1111-
1112-
@Override
1113-
protected void parseNonNullValue(XContentParser parser, List<BytesRef> accumulator) throws IOException {
1114-
var text = parser.textOrNull();
1115-
1116-
if (text != null) {
1117-
accumulator.add(new BytesRef(text));
1118-
}
1119-
}
1120-
1121-
@Override
1122-
public void writeToBlock(List<BytesRef> values, BlockLoader.Builder blockBuilder) {
1123-
var bytesRefBuilder = (BlockLoader.BytesRefBuilder) blockBuilder;
1124-
1125-
for (var value : values) {
1126-
bytesRefBuilder.appendBytesRef(value);
1127-
}
1128-
}
1129-
};
1130-
1131-
return new FallbackSyntheticSourceBlockLoader(
1132-
reader,
1133-
name(),
1134-
IgnoredSourceFieldMapper.ignoredSourceFormat(blContext.indexSettings().getIndexVersionCreated())
1135-
) {
1136-
@Override
1137-
public Builder builder(BlockFactory factory, int expectedCount) {
1138-
return factory.bytesRefs(expectedCount);
1139-
}
1140-
};
1141-
}
1142-
11431091
/**
11441092
* Build an iterator of documents that have the field. This mirrors parseCreateField,
11451093
* using whatever

0 commit comments

Comments
 (0)