Skip to content

Commit 61b51ba

Browse files
authored
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 bd47032 commit 61b51ba

File tree

11 files changed

+15
-91
lines changed

11 files changed

+15
-91
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;
@@ -53,7 +52,7 @@ protected List<Parameter<?>> getParameters() {
5352
}
5453

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

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").setMapping(
9393
XContentFactory.jsonBuilder().startObject().startObject("_doc")
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/DocCountFieldMapper.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,14 @@
3030

3131
import java.io.IOException;
3232
import java.util.Collections;
33-
import java.util.List;
3433

3534
/** Mapper for the doc_count field. */
3635
public class DocCountFieldMapper extends MetadataFieldMapper {
3736

3837
public static final String NAME = "_doc_count";
3938
public static final String CONTENT_TYPE = "_doc_count";
4039

41-
public static final TypeParser PARSER = new ConfigurableTypeParser(
42-
c -> new DocCountFieldMapper(),
43-
c -> new DocCountFieldMapper.Builder());
44-
45-
static class Builder extends MetadataFieldMapper.Builder {
46-
47-
Builder() {
48-
super(NAME);
49-
}
50-
51-
@Override
52-
protected List<Parameter<?>> getParameters() {
53-
return Collections.emptyList();
54-
}
55-
56-
@Override
57-
public DocCountFieldMapper build(ContentPath contentPath) {
58-
return new DocCountFieldMapper();
59-
}
60-
}
40+
public static final TypeParser PARSER = new FixedTypeParser(c -> new DocCountFieldMapper());
6141

6242
public static final class DocCountFieldType extends MappedFieldType {
6343

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

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

9595
@Override
96-
public FieldNamesFieldMapper build(ContentPath contentPath) {
96+
public FieldNamesFieldMapper build() {
9797
if (enabled.getValue().explicit()) {
9898
if (indexVersionCreated.onOrAfter(Version.V_8_0_0)) {
9999
throw new MapperParsingException("The `enabled` setting for the `_field_names` field has been deprecated and "

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

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

131131
@Override
132-
public abstract MetadataFieldMapper build(ContentPath contentPath);
132+
public final MetadataFieldMapper build(ContentPath path) {
133+
return build();
134+
}
135+
136+
public abstract MetadataFieldMapper build();
133137
}
134138

135139
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(String[]::new),
9797
excludes.getValue().toArray(String[]::new));

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.elasticsearch.common.xcontent.XContentType;
4242
import org.elasticsearch.env.Environment;
4343
import org.elasticsearch.index.Index;
44-
import org.elasticsearch.index.mapper.ContentPath;
4544
import org.elasticsearch.index.mapper.FieldMapper;
4645
import org.elasticsearch.index.mapper.MappedFieldType;
4746
import org.elasticsearch.index.mapper.MapperParsingException;
@@ -1575,7 +1574,7 @@ protected List<FieldMapper.Parameter<?>> getParameters() {
15751574
}
15761575

15771576
@Override
1578-
public MetadataFieldMapper build(ContentPath contentPath) {
1577+
public MetadataFieldMapper build() {
15791578
return new MetadataTimestampFieldMapper(enabled.getValue());
15801579
}
15811580
}

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)