Skip to content

Commit ee6cda4

Browse files
Kubik42elasticsearchmachinemartijnvg
authored
Don't return null from syntheticSourceFallbackFieldName() method (#136344)
This to avoid NPE in a later stage. Relates to #136345 --------- Co-authored-by: elasticsearchmachine <[email protected]> Co-authored-by: Martijn van Groningen <[email protected]>
1 parent 88ef3dc commit ee6cda4

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public boolean isWithinMultiField() {
5151
* stored for whatever reason.
5252
*/
5353
public String syntheticSourceFallbackFieldName() {
54-
return isSyntheticSourceEnabled ? name() + "._original" : null;
54+
return name() + "._original";
5555
}
5656

5757
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,7 @@ private SourceLoader.SyntheticFieldLoader syntheticFieldLoader(String fullFieldN
16931693
// since we don't know whether the delegate field loader can be used for synthetic source until parsing, we need to check both this
16941694
// field and the delegate
16951695

1696-
// first field loader - to check whether the field's value was stored under this match_only_text field
1696+
// first field loader - to check whether the field's value was stored under this text field
16971697
final String fieldName = fieldType().syntheticSourceFallbackFieldName();
16981698
final var thisFieldLayer = new CompositeSyntheticFieldLoader.StoredFieldLayer(fieldName) {
16991699
@Override

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,8 +1122,6 @@ public void testValueExceedsIgnoreAboveWhenSyntheticSourceDisabled() throws IOEx
11221122

11231123
// then
11241124

1125-
// since synthetic source is disabled, the fallback field name shouldn't exist
1126-
assertThat(mapper.fieldType().syntheticSourceFallbackFieldName(), Matchers.nullValue());
11271125
// despite exceeding ignore_above, because synthetic source is disabled, we don't expect to store anything
11281126
assertThat(doc.rootDoc().getField(mapper.fieldType() + "_original"), Matchers.nullValue());
11291127
}

x-pack/plugin/logsdb/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ base {
2424

2525
restResources {
2626
restApi {
27-
include 'bulk', 'search', '_common', 'indices', 'index', 'cluster', 'data_stream', 'ingest', 'cat', 'capabilities', 'esql.query', 'field_caps'
27+
include 'bulk', 'search', '_common', 'indices', 'index', 'cluster', 'data_stream', 'ingest', 'cat', 'capabilities', 'esql.query', 'field_caps', 'get'
2828
}
2929
}
3030

x-pack/plugin/logsdb/src/yamlRestTest/resources/rest-api-spec/test/40_source_mode_setting.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,46 @@ use no-op _source.mode attr:
489489
index: test
490490

491491
- match: { test.settings.index.mapping.source.mode: synthetic }
492+
493+
---
494+
use deprecated _source.mode attr:
495+
- requires:
496+
test_runner_features: [ "warnings" ]
497+
498+
- do:
499+
warnings:
500+
- "Configuring source mode in mappings is deprecated and will be removed in future versions. Use [index.mapping.source.mode] index setting instead."
501+
indices.create:
502+
index: test
503+
body:
504+
mappings:
505+
_source:
506+
mode: synthetic
507+
properties:
508+
cloud:
509+
properties:
510+
account:
511+
properties:
512+
full_text:
513+
type: text
514+
fields:
515+
keyword:
516+
type: keyword
517+
ignore_above: 256
518+
519+
- do:
520+
index:
521+
index: test_index
522+
id: "1"
523+
body:
524+
cloud:
525+
account:
526+
full_text: "test"
527+
- match: { result: created }
528+
529+
- do:
530+
get:
531+
index: test_index
532+
id: "1"
533+
force_synthetic_source: true
534+
- match: { _source: { cloud: {account: {full_text: "test" } } } }

0 commit comments

Comments
 (0)