Skip to content

Commit 88a2aeb

Browse files
authored
Remove the 'array value parser' marker interface. (#57571)
This PR replaces the marker interface with the method FieldMapper#parsesArrayValue. I find this cleaner and it will help with the fields retrieval work (#55363). The refactor also ensures that only field mappers can declare they parse array values. Previously other types like ObjectMapper could implement the marker interface and be passed array values, which doesn't make sense.
1 parent 0df456c commit 88a2aeb

File tree

8 files changed

+35
-39
lines changed

8 files changed

+35
-39
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ protected void parseCreateField(ParseContext context) throws IOException {
305305
protected abstract void addDocValuesFields(String name, Processed geometry, List<IndexableField> fields, ParseContext context);
306306
protected abstract void addMultiFields(ParseContext context, Processed geometry) throws IOException;
307307

308+
@Override
309+
public final boolean parsesArrayValue() {
310+
return true;
311+
}
312+
308313
/** parsing logic for geometry indexing */
309314
@Override
310315
public void parse(ParseContext context) throws IOException {

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

-29
This file was deleted.

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
* This field can also be extended to add search criteria to suggestions
8484
* for query-time filtering and boosting (see {@link ContextMappings}
8585
*/
86-
public class CompletionFieldMapper extends FieldMapper implements ArrayValueMapperParser {
86+
public class CompletionFieldMapper extends FieldMapper {
8787
public static final String CONTENT_TYPE = "completion";
8888

8989
/**
@@ -426,6 +426,11 @@ public CompletionFieldType fieldType() {
426426
return (CompletionFieldType) super.fieldType();
427427
}
428428

429+
@Override
430+
public boolean parsesArrayValue() {
431+
return true;
432+
}
433+
429434
/**
430435
* Parses and indexes inputs
431436
*

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ private static void parseArray(ParseContext context, ObjectMapper parentMapper,
522522
// There is a concrete mapper for this field already. Need to check if the mapper
523523
// expects an array, if so we pass the context straight to the mapper and if not
524524
// we serialize the array components
525-
if (mapper instanceof ArrayValueMapperParser) {
525+
if (parsesArrayValue(mapper)) {
526526
parseObjectOrField(context, mapper);
527527
} else {
528528
parseNonDynamicArray(context, parentMapper, lastFieldName, arrayFieldName);
@@ -543,7 +543,7 @@ private static void parseArray(ParseContext context, ObjectMapper parentMapper,
543543
Mapper.BuilderContext builderContext = new Mapper.BuilderContext(context.indexSettings().getSettings(), context.path());
544544
mapper = builder.build(builderContext);
545545
assert mapper != null;
546-
if (mapper instanceof ArrayValueMapperParser) {
546+
if (parsesArrayValue(mapper)) {
547547
context.addDynamicMapper(mapper);
548548
context.path().add(arrayFieldName);
549549
parseObjectOrField(context, mapper);
@@ -562,6 +562,10 @@ private static void parseArray(ParseContext context, ObjectMapper parentMapper,
562562
}
563563
}
564564

565+
private static boolean parsesArrayValue(Mapper mapper) {
566+
return mapper instanceof FieldMapper && ((FieldMapper) mapper).parsesArrayValue();
567+
}
568+
565569
private static void parseNonDynamicArray(ParseContext context, ObjectMapper mapper,
566570
final String lastFieldName, String arrayFieldName) throws IOException {
567571
XContentParser parser = context.parser();

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

+10
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,16 @@ public CopyTo copyTo() {
273273
return copyTo;
274274
}
275275

276+
/**
277+
* Whether this mapper can handle an array value during document parsing. If true,
278+
* when an array is encountered during parsing, the document parser will pass the
279+
* whole array to the mapper. If false, the array is split into individual values
280+
* and each value is passed to the mapper for parsing.
281+
*/
282+
public boolean parsesArrayValue() {
283+
return false;
284+
}
285+
276286
/**
277287
* Parse the field value using the provided {@link ParseContext}.
278288
*/

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
*
4545
* Uses lucene 6 LatLonPoint encoding
4646
*/
47-
public class GeoPointFieldMapper extends AbstractPointGeometryFieldMapper<List<? extends GeoPoint>, List<? extends GeoPoint>>
48-
implements ArrayValueMapperParser {
47+
public class GeoPointFieldMapper extends AbstractPointGeometryFieldMapper<List<? extends GeoPoint>, List<? extends GeoPoint>> {
4948
public static final String CONTENT_TYPE = "geo_point";
5049

5150
public static class Builder extends AbstractPointGeometryFieldMapper.Builder<Builder, GeoPointFieldType> {

x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/index/mapper/PointFieldMapper.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.elasticsearch.common.settings.Settings;
1414
import org.elasticsearch.common.xcontent.XContentParser;
1515
import org.elasticsearch.index.mapper.AbstractPointGeometryFieldMapper;
16-
import org.elasticsearch.index.mapper.ArrayValueMapperParser;
1716
import org.elasticsearch.index.mapper.MappedFieldType;
1817
import org.elasticsearch.index.mapper.ParseContext;
1918
import org.elasticsearch.xpack.spatial.common.CartesianPoint;
@@ -30,8 +29,7 @@
3029
*
3130
* Uses lucene 8 XYPoint encoding
3231
*/
33-
public class PointFieldMapper extends AbstractPointGeometryFieldMapper<List<? extends CartesianPoint>, List<? extends CartesianPoint>>
34-
implements ArrayValueMapperParser {
32+
public class PointFieldMapper extends AbstractPointGeometryFieldMapper<List<? extends CartesianPoint>, List<? extends CartesianPoint>> {
3533
public static final String CONTENT_TYPE = "point";
3634

3735
public static class Builder extends AbstractPointGeometryFieldMapper.Builder<Builder, PointFieldType> {

x-pack/plugin/vectors/src/main/java/org/elasticsearch/xpack/vectors/mapper/DenseVectorFieldMapper.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.elasticsearch.common.xcontent.XContentParser.Token;
1919
import org.elasticsearch.common.xcontent.support.XContentMapValues;
2020
import org.elasticsearch.index.fielddata.IndexFieldData;
21-
import org.elasticsearch.index.mapper.ArrayValueMapperParser;
2221
import org.elasticsearch.index.mapper.FieldMapper;
2322
import org.elasticsearch.index.mapper.MappedFieldType;
2423
import org.elasticsearch.index.mapper.Mapper;
@@ -40,7 +39,7 @@
4039
/**
4140
* A {@link FieldMapper} for indexing a dense vector of floats.
4241
*/
43-
public class DenseVectorFieldMapper extends FieldMapper implements ArrayValueMapperParser {
42+
public class DenseVectorFieldMapper extends FieldMapper {
4443

4544
public static final String CONTENT_TYPE = "dense_vector";
4645
public static short MAX_DIMS_COUNT = 2048; //maximum allowed number of dimensions
@@ -173,6 +172,11 @@ public DenseVectorFieldType fieldType() {
173172
return (DenseVectorFieldType) super.fieldType();
174173
}
175174

175+
@Override
176+
public boolean parsesArrayValue() {
177+
return true;
178+
}
179+
176180
@Override
177181
public void parse(ParseContext context) throws IOException {
178182
if (context.externalValueSet()) {

0 commit comments

Comments
 (0)