Skip to content

Commit b114cd4

Browse files
committed
Changes
1 parent 2d28a6d commit b114cd4

File tree

9 files changed

+22
-15
lines changed

9 files changed

+22
-15
lines changed

plugins/mapper-size/src/main/java/org/elasticsearch/index/mapper/size/SizeFieldMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void postParse(DocumentParserContext context) {
9090
return;
9191
}
9292
// TODO: Will be incorrect after ingest modifications
93-
final int value = context.sourceToParse().modernSource().originalSourceSize();
93+
final int value = context.sourceToParse().source().originalSourceSize();
9494
NumberType.INTEGER.addFields(context.doc(), fullPath(), value, true, true, true);
9595
}
9696

server/src/main/java/org/elasticsearch/action/index/ModernSource.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ public ESONFlat structuredSource() {
9090
return structuredSource;
9191
}
9292

93+
public boolean isSourceEmpty() {
94+
// TODO: check this logic. What does an empty source get converted into?
95+
if (structuredSource != null) {
96+
return false;
97+
} else {
98+
return originalSource == null || originalSource.length() == 0;
99+
}
100+
101+
}
102+
93103
@Override
94104
public boolean equals(Object o) {
95105
// TODO: Improve

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ public final class DocumentParser {
7979
* @throws DocumentParsingException whenever there's a problem parsing the document
8080
*/
8181
public ParsedDocument parseDocument(SourceToParse source, MappingLookup mappingLookup) throws DocumentParsingException {
82-
if (source.source() != null && source.source().length() == 0) {
82+
ModernSource modernSource = source.source();
83+
if (modernSource.isSourceEmpty()) {
8384
throw new DocumentParsingException(new XContentLocation(0, 0), "failed to parse, document is empty");
8485
}
8586
final RootDocumentParserContext context;
@@ -123,7 +124,7 @@ public String documentDescription() {
123124

124125
private XContentParser getParser(SourceToParse source, XContentType xContentType) throws IOException {
125126
XContentParserConfiguration config = parserConfiguration.withIncludeSourceOnError(source.getIncludeSourceOnError());
126-
ModernSource modernSource = source.modernSource();
127+
ModernSource modernSource = source.source();
127128
if (modernSource.isStructured()) {
128129
return new ESONXContentParser(modernSource.structuredSource(), config.registry(), config.deprecationHandler(), xContentType);
129130
} else {
@@ -184,7 +185,7 @@ private static void executeIndexTimeScripts(DocumentParserContext context) {
184185
fto
185186
)
186187
).build(new IndexFieldDataCache.None(), new NoneCircuitBreakerService()),
187-
(ctx, doc) -> Source.fromBytes(context.sourceToParse().modernSource().originalSourceBytes())
188+
(ctx, doc) -> Source.fromBytes(context.sourceToParse().source().originalSourceBytes())
188189
);
189190
// field scripts can be called both by the loop at the end of this method and via
190191
// the document reader, so to ensure that we don't run them multiple times we

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ public boolean isComplete() {
436436
@Override
437437
public void preParse(DocumentParserContext context) throws IOException {
438438
SourceToParse sourceToParse = context.sourceToParse();
439-
ModernSource modernSource = sourceToParse.modernSource();
439+
ModernSource modernSource = sourceToParse.source();
440440
XContentType contentType = sourceToParse.getXContentType();
441441

442442
final var storedSource = stored()

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,7 @@ public SourceToParse(
9090
this(id, source, xContentType, routing, dynamicTemplates, true, XContentMeteringParserDecorator.NOOP);
9191
}
9292

93-
public BytesReference source() {
94-
return this.modernSource().originalSourceBytes();
95-
}
96-
97-
public ModernSource modernSource() {
93+
public ModernSource source() {
9894
return this.modernSource;
9995
}
10096

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static BytesRef createField(
7171
|| id.equals(
7272
indexRouting.createId(
7373
context.sourceToParse().getXContentType(),
74-
context.sourceToParse().modernSource().originalSourceBytes(),
74+
context.sourceToParse().source().originalSourceBytes(),
7575
suffix
7676
)
7777
);

server/src/test/java/org/elasticsearch/index/mapper/vectors/SparseVectorFieldMapperTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ public void testValueFetcher() throws Exception {
451451
var valueFetcher = fieldType.valueFetcher(searchContext, null);
452452
valueFetcher.setNextReader(leafReader.getContext());
453453

454-
var source = Source.fromBytes(sourceToParse.modernSource().originalSourceBytes());
454+
var source = Source.fromBytes(sourceToParse.source().originalSourceBytes());
455455
var result = valueFetcher.fetchValues(source, 0, List.of());
456456
assertThat(result.size(), equalTo(1));
457457
assertThat(result.get(0), instanceOf(Map.class));

test/framework/src/main/java/org/elasticsearch/index/mapper/MapperTestCase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,11 @@ private void assertIgnoreMalformedFalse(
283283
});
284284
DocumentParsingException e = expectThrows(
285285
DocumentParsingException.class,
286-
"didn't throw while parsing " + source.source().utf8ToString(),
286+
"didn't throw while parsing " + source.source().originalSourceBytes().utf8ToString(),
287287
() -> mapperService.documentMapper().parse(source)
288288
);
289289
assertThat(
290-
"incorrect exception while parsing " + source.source().utf8ToString(),
290+
"incorrect exception while parsing " + source.source().originalSourceBytes().utf8ToString(),
291291
e.getCause().getMessage(),
292292
exceptionMessageMatcher
293293
);

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/highlight/SemanticTextHighlighterTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ private void assertHighlightOneDoc(
274274
getOnlyLeafReader(reader).getContext(),
275275
docID,
276276
Map.of(),
277-
Source.fromBytes(source.modernSource().originalSourceBytes()),
277+
Source.fromBytes(source.source().originalSourceBytes()),
278278
new RankDoc(docID, Float.NaN, 0)
279279
);
280280
try {

0 commit comments

Comments
 (0)