Skip to content

Commit 53ded56

Browse files
committed
Cleaned up
1 parent 3779789 commit 53ded56

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -715,11 +715,11 @@ protected SyntheticSourceSupport syntheticSourceSupport() {
715715
}
716716

717717
private SourceLoader.SyntheticFieldLoader syntheticFieldLoader(String fullFieldName, String leafFieldName) {
718-
// match_only_text is not stored for space efficiency, except when synthetic source is enabled as synthetic source
719-
// needs something to load to reconstruct source. In such cases, we *might* store this field or we *might* rely
720-
// on a delegate field if one exists. Because of this uncertainty, we need multiple field loaders.
718+
// we're using two field loaders here because we don't know who was responsible for storing this field to support synthetic source
719+
// on one hand, if a delegate keyword field exists, then it might've stored the field. However, this is not true if said field was
720+
// ignored during indexing (ex. it tripped ignore_above). Because of this uncertainty, we need multiple field loaders.
721721

722-
// first field loader, representing this field
722+
// first field loader - to check whether the field's value was stored under this match_only_text field
723723
final String fieldName = fieldType().syntheticSourceFallbackFieldName();
724724
final var thisFieldLayer = new CompositeSyntheticFieldLoader.StoredFieldLayer(fieldName) {
725725
@Override
@@ -735,7 +735,7 @@ protected void writeValue(Object value, XContentBuilder b) throws IOException {
735735

736736
final CompositeSyntheticFieldLoader fieldLoader = new CompositeSyntheticFieldLoader(leafFieldName, fullFieldName, thisFieldLayer);
737737

738-
// second loader, representing a delegate field, if one exists
738+
// second loader - to check whether the field's value was stored by a keyword delegate field
739739
var kwd = TextFieldMapper.SyntheticSourceHelper.getKeywordFieldMapperForSyntheticSource(this);
740740
if (kwd != null) {
741741
// merge the two field loaders into one

plugins/mapper-annotated-text/src/main/java/org/elasticsearch/index/mapper/annotatedtext/AnnotatedTextFieldMapper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,10 @@ protected void write(XContentBuilder b, Object value) throws IOException {
625625
}
626626

627627
private SourceLoader.SyntheticFieldLoader syntheticFieldLoader(String fullFieldName, String leafFieldName) {
628-
// since we don't know whether the delegate field loader can be used for synthetic source until parsing, we
629-
// need to check both this field and the delegate
628+
// since we don't know whether the delegate field loader can be used for synthetic source until parsing, we need to check both this
629+
// field and the delegate
630630

631-
// first field loader, representing this field
631+
// first field loader - to check whether the field's value was stored under this match_only_text field
632632
final String fieldName = fieldType().syntheticSourceFallbackFieldName();
633633
final var thisFieldLayer = new CompositeSyntheticFieldLoader.StoredFieldLayer(fieldName) {
634634
@Override
@@ -639,7 +639,7 @@ protected void writeValue(Object value, XContentBuilder b) throws IOException {
639639

640640
final CompositeSyntheticFieldLoader fieldLoader = new CompositeSyntheticFieldLoader(leafFieldName, fullFieldName, thisFieldLayer);
641641

642-
// second loader, representing a delegate field, if one exists
642+
// second loader - to check whether the field's value was stored by a keyword delegate field
643643
var kwd = TextFieldMapper.SyntheticSourceHelper.getKeywordFieldMapperForSyntheticSource(this);
644644
if (kwd != null) {
645645
// merge the two field loaders into one

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ public boolean newDynamicStringField(DocumentParserContext context, String name)
341341
indexSettings.getIndexVersionCreated(),
342342
indexSettings.getMode(),
343343
context.indexAnalyzers(),
344-
mapperBuilderContext.isSourceSynthetic(),
344+
SourceFieldMapper.isSynthetic(indexSettings),
345345
false
346346
).addMultiField(
347347
new KeywordFieldMapper.Builder("keyword", context.indexSettings().getIndexVersionCreated(), true).ignoreAbove(256)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,12 @@ private static FielddataFrequencyFilter parseFrequencyFilter(String name, Mappin
240240
public static class Builder extends TextFamilyFieldMapper.Builder {
241241

242242
private final IndexVersion indexCreatedVersion;
243+
private final Parameter<Boolean> store;
243244
private final Parameter<Boolean> norms;
244245

245246
private final IndexMode indexMode;
246247

247248
private final Parameter<Boolean> index = Parameter.indexParam(m -> ((TextFieldMapper) m).index, true);
248-
private Parameter<Boolean> store;
249249

250250
final Parameter<SimilarityProvider> similarity = TextParams.similarity(m -> ((TextFieldMapper) m).similarity);
251251

@@ -1606,10 +1606,10 @@ protected void write(XContentBuilder b, Object value) throws IOException {
16061606
}
16071607

16081608
private SourceLoader.SyntheticFieldLoader syntheticFieldLoader(String fullFieldName, String leafFieldName) {
1609-
// since we don't know whether the delegate field loader can be used for synthetic source until parsing, we
1610-
// need to check both this field and the delegate
1609+
// since we don't know whether the delegate field loader can be used for synthetic source until parsing, we need to check both this
1610+
// field and the delegate
16111611

1612-
// first field loader, representing this field
1612+
// first field loader - to check whether the field's value was stored under this match_only_text field
16131613
final String fieldName = fieldType().syntheticSourceFallbackFieldName();
16141614
final var thisFieldLayer = new CompositeSyntheticFieldLoader.StoredFieldLayer(fieldName) {
16151615
@Override
@@ -1620,7 +1620,7 @@ protected void writeValue(Object value, XContentBuilder b) throws IOException {
16201620

16211621
final CompositeSyntheticFieldLoader fieldLoader = new CompositeSyntheticFieldLoader(leafFieldName, fullFieldName, thisFieldLayer);
16221622

1623-
// second loader, representing a delegate field, if one exists
1623+
// second loader - to check whether the field's value was stored by a keyword delegate field
16241624
var kwd = TextFieldMapper.SyntheticSourceHelper.getKeywordFieldMapperForSyntheticSource(this);
16251625
if (kwd != null) {
16261626
// merge the two field loaders into one

server/src/test/java/org/elasticsearch/index/mapper/KeywordFieldMapperTests.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ public void test_isIgnoreAboveSet_returns_true_when_ignore_above_is_provided() t
978978
assertTrue(mapper.fieldType().isIgnoreAboveSet());
979979
}
980980

981-
public void test_isIgnoreAboveSet_returns_true_when_ignore_above_is_missing() throws IOException {
981+
public void test_isIgnoreAboveSet_returns_false_when_ignore_above_is_missing() throws IOException {
982982
// given
983983
MapperService mapperService = createSytheticSourceMapperService(mapping(b -> {
984984
b.startObject("potato");
@@ -1058,7 +1058,7 @@ public void test_value_is_not_ignored_when_it_does_not_exceed_ignore_above_and_f
10581058
assertFalse(mapper.fieldType().isIgnored("this value is too short to be ignored"));
10591059
}
10601060

1061-
public void test_value_exceeds_ignore_above_and_field_is_not_a_multi_field() throws IOException {
1061+
public void test_value_is_stored_when_it_exceeds_ignore_above_and_field_is_not_a_multi_field() throws IOException {
10621062
// given
10631063
MapperService mapperService = createSytheticSourceMapperService(mapping(b -> {
10641064
b.startObject("potato");
@@ -1077,7 +1077,7 @@ public void test_value_exceeds_ignore_above_and_field_is_not_a_multi_field() thr
10771077
assertThat(doc.rootDoc().getField(mapper.fieldType().syntheticSourceFallbackFieldName()), Matchers.notNullValue());
10781078
}
10791079

1080-
public void test_value_exceeds_ignore_above_and_field_is_a_multi_field() throws IOException {
1080+
public void test_value_is_not_stored_when_it_exceeds_ignore_above_and_field_is_a_multi_field() throws IOException {
10811081
// given
10821082
MapperService mapperService = createSytheticSourceMapperService(mapping(b -> {
10831083
b.startObject("potato").field("type", "text");
@@ -1122,12 +1122,11 @@ public void test_value_does_not_exceed_ignore_above_and_field_is_a_multi_field()
11221122

11231123
// when
11241124
KeywordFieldMapper mapper = (KeywordFieldMapper) mapperService.documentMapper().mappers().getMapper("potato.tomato");
1125-
ParsedDocument doc = mapperService.documentMapper().parse(source(b -> { b.field("potato", "this value is too long"); }));
1125+
ParsedDocument doc = mapperService.documentMapper().parse(source(b -> { b.field("potato", "this value is short"); }));
11261126

11271127
// then
11281128

1129-
// despite exceeding ignore_above, because the field is a multi field, we don't need to store anything extra in Lucene as _source
1130-
// can be reconstructed via the parent
1129+
// we don't expect to store anything extra when ignore_above isn't tripped as we can rely on doc_values for source
11311130
assertThat(doc.rootDoc().getField(mapper.fieldType().syntheticSourceFallbackFieldName()), Matchers.nullValue());
11321131
}
11331132

@@ -1146,6 +1145,8 @@ public void test_value_exceeds_ignore_above_when_synthetic_source_disabled() thr
11461145

11471146
// then
11481147

1148+
// since synthetic source is disabled, the fallback field name shouldn't exist
1149+
assertThat(mapper.fieldType().syntheticSourceFallbackFieldName(), Matchers.nullValue());
11491150
// despite exceeding ignore_above, because synthetic source is disabled, we don't expect to store anything
11501151
assertThat(doc.rootDoc().getField(mapper.fieldType() + "_original"), Matchers.nullValue());
11511152
}

0 commit comments

Comments
 (0)