Skip to content

Commit 05458c6

Browse files
committed
address review comments
1 parent 92ed93d commit 05458c6

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

docs/changelog/119183.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

server/src/main/java/org/elasticsearch/index/engine/TranslogDirectoryReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ private void readStoredFieldsDirectly(StoredFieldVisitor visitor) throws IOExcep
440440
SourceFieldMapper mapper = mappingLookup.getMapping().getMetadataMapperByClass(SourceFieldMapper.class);
441441
if (mapper != null) {
442442
try {
443-
sourceBytes = mapper.applyFilters(null, sourceBytes, null);
443+
sourceBytes = mapper.applyFilters(mappingLookup, sourceBytes, null);
444444
} catch (IOException e) {
445445
throw new IOException("Failed to reapply filters after reading from translog", e);
446446
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public boolean isComplete() {
405405
public void preParse(DocumentParserContext context) throws IOException {
406406
BytesReference originalSource = context.sourceToParse().source();
407407
XContentType contentType = context.sourceToParse().getXContentType();
408-
final BytesReference adaptedSource = applyFilters(context, originalSource, contentType);
408+
final BytesReference adaptedSource = applyFilters(context.mappingLookup(), originalSource, contentType);
409409

410410
if (adaptedSource != null) {
411411
final BytesRef ref = adaptedSource.toBytesRef();
@@ -434,17 +434,17 @@ public void preParse(DocumentParserContext context) throws IOException {
434434

435435
@Nullable
436436
public BytesReference applyFilters(
437-
@Nullable DocumentParserContext context,
437+
@Nullable MappingLookup mappingLookup,
438438
@Nullable BytesReference originalSource,
439439
@Nullable XContentType contentType
440440
) throws IOException {
441441
if (stored() == false || originalSource == null) {
442442
return null;
443443
}
444444
var modSourceFilter = sourceFilter;
445-
if (context != null
446-
&& InferenceMetadataFieldsMapper.isEnabled(context.mappingLookup())
447-
&& context.mappingLookup().inferenceFields().isEmpty() == false) {
445+
if (mappingLookup != null
446+
&& InferenceMetadataFieldsMapper.isEnabled(mappingLookup)
447+
&& mappingLookup.inferenceFields().isEmpty() == false) {
448448
/**
449449
* Removes {@link InferenceMetadataFieldsMapper} content from _source.
450450
* This content is re-generated at query time (if requested) using stored fields and doc values.

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/mapper/SemanticInferenceMetadataFieldsMapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ public ValueFetcher valueFetcher(MappingLookup mappingLookup, Function<Query, Bi
6262
if (ft instanceof SemanticTextFieldMapper.SemanticTextFieldType semanticTextFieldType) {
6363
fieldFetchers.put(inferenceField, semanticTextFieldType.valueFetcherWithInferenceResults(bitSetCache, searcher));
6464
} else {
65-
throw new IllegalArgumentException("Illegal format for field [" + name() + "], got " + ft.typeName());
65+
throw new IllegalArgumentException(
66+
"Invalid inference field [" + ft.name() + "]. Expected field type [semantic_text] but got [" + ft.typeName() + "]"
67+
);
6668
}
6769
}
6870
if (fieldFetchers.isEmpty()) {

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapperTests.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,20 @@ public void testInvalidInferenceEndpoints() {
282282
{
283283
Exception e = expectThrows(
284284
MapperParsingException.class,
285-
() -> createMapperService(fieldMapping(b -> b.field("type", "semantic_text").field(INFERENCE_ID_FIELD, "")), false)
285+
() -> createMapperService(
286+
fieldMapping(b -> b.field("type", "semantic_text").field(INFERENCE_ID_FIELD, "")),
287+
useLegacyFormat
288+
)
286289
);
287290
assertThat(e.getMessage(), containsString("[inference_id] on mapper [field] of type [semantic_text] must not be empty"));
288291
}
289292
{
290293
Exception e = expectThrows(
291294
MapperParsingException.class,
292-
() -> createMapperService(fieldMapping(b -> b.field("type", "semantic_text").field(SEARCH_INFERENCE_ID_FIELD, "")), false)
295+
() -> createMapperService(
296+
fieldMapping(b -> b.field("type", "semantic_text").field(SEARCH_INFERENCE_ID_FIELD, "")),
297+
useLegacyFormat
298+
)
293299
);
294300
assertThat(e.getMessage(), containsString("[search_inference_id] on mapper [field] of type [semantic_text] must not be empty"));
295301
}
@@ -511,8 +517,9 @@ private static void assertSemanticTextField(MapperService mapperService, String
511517
assertFalse(textFieldMapper.fieldType().isIndexed());
512518
assertFalse(textFieldMapper.fieldType().hasDocValues());
513519
} else {
514-
// TODO: Check for offsets mapper here
515520
assertNull(textMapper);
521+
var offsetMapper = semanticTextFieldType.getOffsetsField();
522+
assertThat(offsetMapper, instanceOf(OffsetSourceFieldMapper.class));
516523
}
517524

518525
if (expectedModelSettings) {

0 commit comments

Comments
 (0)