Skip to content

Commit e3a30fc

Browse files
committed
MetadataFieldMapper.Builder.build() doesn't need ContentPath (#64636)
Metadata fields are always instantiated at the root of a document, so they don't need to take the ContentPath in their build() methods. Also converts a couple of metadata parsers from Configurable to Fixed, as they don't have any parameters.
1 parent 76c5907 commit e3a30fc

File tree

11 files changed

+15
-71
lines changed

11 files changed

+15
-71
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.elasticsearch.index.mapper.size;
2121

2222
import org.elasticsearch.common.Explicit;
23-
import org.elasticsearch.index.mapper.ContentPath;
2423
import org.elasticsearch.index.mapper.FieldMapper;
2524
import org.elasticsearch.index.mapper.MappedFieldType;
2625
import org.elasticsearch.index.mapper.MetadataFieldMapper;
@@ -54,7 +53,7 @@ protected List<Parameter<?>> getParameters() {
5453
}
5554

5655
@Override
57-
public SizeFieldMapper build(ContentPath contentPath) {
56+
public SizeFieldMapper build() {
5857
return new SizeFieldMapper(enabled.getValue(), new NumberFieldType(NAME, NumberType.INTEGER));
5958
}
6059
}

server/src/internalClusterTest/java/org/elasticsearch/index/mapper/ExternalValuesMapperIntegrationIT.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ public void testHighlightingOnCustomString() throws Exception {
9191
public void testExternalValues() throws Exception {
9292
prepareCreate("test-idx").addMapping("type",
9393
XContentFactory.jsonBuilder().startObject().startObject("type")
94-
.startObject(ExternalMetadataMapper.CONTENT_TYPE)
95-
.endObject()
9694
.startObject("properties")
9795
.startObject("field").field("type", ExternalMapperPlugin.EXTERNAL).endObject()
9896
.endObject()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected List<Parameter<?>> getParameters() {
6868
}
6969

7070
@Override
71-
public AllFieldMapper build(ContentPath contentPath) {
71+
public AllFieldMapper build() {
7272
if (enabled.getValue().value()) {
7373
throw new IllegalArgumentException("[_all] is disabled in this version.");
7474
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected List<Parameter<?>> getParameters() {
9797
}
9898

9999
@Override
100-
public FieldNamesFieldMapper build(ContentPath contentPath) {
100+
public FieldNamesFieldMapper build() {
101101
if (enabled.getValue().explicit()) {
102102
deprecationLogger.deprecate("field_names_enabled_parameter", ENABLED_DEPRECATION_MESSAGE);
103103
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ boolean isConfigured() {
128128
}
129129

130130
@Override
131-
public abstract MetadataFieldMapper build(ContentPath contentPath);
131+
public final MetadataFieldMapper build(ContentPath path) {
132+
return build();
133+
}
134+
135+
public abstract MetadataFieldMapper build();
132136
}
133137

134138
protected MetadataFieldMapper(MappedFieldType mappedFieldType) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected List<Parameter<?>> getParameters() {
7171
}
7272

7373
@Override
74-
public RoutingFieldMapper build(ContentPath contentPath) {
74+
public RoutingFieldMapper build() {
7575
return new RoutingFieldMapper(required.getValue());
7676
}
7777
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ protected List<Parameter<?>> getParameters() {
9191
}
9292

9393
@Override
94-
public SourceFieldMapper build(ContentPath contentPath) {
94+
public SourceFieldMapper build() {
9595
return new SourceFieldMapper(enabled.getValue(),
9696
includes.getValue().toArray(new String[0]),
9797
excludes.getValue().toArray(new String[0]));

server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateServiceTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import org.elasticsearch.common.xcontent.XContentType;
4141
import org.elasticsearch.env.Environment;
4242
import org.elasticsearch.index.Index;
43-
import org.elasticsearch.index.mapper.ContentPath;
4443
import org.elasticsearch.index.mapper.FieldMapper;
4544
import org.elasticsearch.index.mapper.MappedFieldType;
4645
import org.elasticsearch.index.mapper.MapperParsingException;
@@ -1631,7 +1630,7 @@ protected List<FieldMapper.Parameter<?>> getParameters() {
16311630
}
16321631

16331632
@Override
1634-
public MetadataFieldMapper build(ContentPath contentPath) {
1633+
public MetadataFieldMapper build() {
16351634
return new MetadataTimestampFieldMapper(enabled.getValue());
16361635
}
16371636
}

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

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@
2222
import org.apache.lucene.document.Field.Store;
2323
import org.apache.lucene.document.StringField;
2424

25-
import java.io.IOException;
26-
import java.util.Collections;
27-
import java.util.Iterator;
28-
import java.util.List;
29-
3025
public class ExternalMetadataMapper extends MetadataFieldMapper {
3126

3227
static final String CONTENT_TYPE = "_external_root";
@@ -37,39 +32,16 @@ protected ExternalMetadataMapper() {
3732
super(new BooleanFieldMapper.BooleanFieldType(FIELD_NAME));
3833
}
3934

40-
@Override
41-
public Iterator<Mapper> iterator() {
42-
return Collections.emptyIterator();
43-
}
44-
4535
@Override
4636
protected String contentType() {
4737
return CONTENT_TYPE;
4838
}
4939

5040
@Override
51-
public void postParse(ParseContext context) throws IOException {
41+
public void postParse(ParseContext context) {
5242
context.doc().add(new StringField(FIELD_NAME, FIELD_VALUE, Store.YES));
5343
}
5444

55-
public static class Builder extends MetadataFieldMapper.Builder {
56-
57-
protected Builder() {
58-
super(FIELD_NAME);
59-
}
60-
61-
@Override
62-
protected List<Parameter<?>> getParameters() {
63-
return Collections.emptyList();
64-
}
65-
66-
@Override
67-
public ExternalMetadataMapper build(ContentPath contentPath) {
68-
return new ExternalMetadataMapper();
69-
}
70-
71-
}
72-
73-
public static final TypeParser PARSER = new ConfigurableTypeParser(c -> new ExternalMetadataMapper(), c -> new Builder());
45+
public static final TypeParser PARSER = new FixedTypeParser(c -> new ExternalMetadataMapper());
7446

7547
}

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

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727

2828
import java.io.IOException;
2929
import java.util.Collections;
30-
import java.util.Iterator;
31-
import java.util.List;
3230
import java.util.Map;
3331

3432
/**
@@ -58,37 +56,12 @@ protected void parseCreateField(ParseContext context) throws IOException {
5856
}
5957
}
6058

61-
@Override
62-
public Iterator<Mapper> iterator() {
63-
return Collections.emptyIterator();
64-
}
65-
6659
@Override
6760
protected String contentType() {
6861
return CONTENT_TYPE;
6962
}
7063

71-
public static class Builder extends MetadataFieldMapper.Builder {
72-
73-
protected Builder() {
74-
super(FIELD_NAME);
75-
}
76-
77-
@Override
78-
protected List<Parameter<?>> getParameters() {
79-
return Collections.emptyList();
80-
}
81-
82-
@Override
83-
public MockMetadataMapper build(ContentPath contentPath) {
84-
return new MockMetadataMapper();
85-
}
86-
}
87-
88-
public static final TypeParser PARSER = new ConfigurableTypeParser(
89-
c -> new MockMetadataMapper(),
90-
c -> new MockMetadataMapper.Builder()) {
91-
};
64+
public static final TypeParser PARSER = new FixedTypeParser(c -> new MockMetadataMapper());
9265
}
9366

9467
@Override

0 commit comments

Comments
 (0)