Skip to content

Commit 0f9c196

Browse files
committed
Address code review feedback.
1 parent 66741fc commit 0f9c196

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,8 @@ private static void parseObjectOrField(ParseContext context, Mapper mapper) thro
469469
} else if (mapper instanceof FieldAliasMapper) {
470470
throw new IllegalArgumentException("Cannot write to a field alias [" + mapper.name() + "].");
471471
} else {
472-
throw new IllegalStateException("The provided mapper [" + mapper.name() + "] has an unrecognized type.");
472+
throw new IllegalStateException("The provided mapper [" + mapper.name() + "] has an unrecognized type [" +
473+
mapper.getClass().getSimpleName() + "].");
473474
}
474475
}
475476

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@
2727
import java.util.Iterator;
2828
import java.util.Map;
2929

30-
public class FieldAliasMapper extends Mapper {
30+
/**
31+
* A mapper for field aliases.
32+
*
33+
* A field alias has no concrete field mappings of its own, but instead points to another field by
34+
* its path. Once defined, an alias can be used in place of the concrete field name in search requests.
35+
*/
36+
public final class FieldAliasMapper extends Mapper {
3137
public static final String CONTENT_TYPE = "alias";
3238

3339
public static class Names {
@@ -89,7 +95,7 @@ public Mapper.Builder parse(String name, Map<String, Object> node, ParserContext
8995
Object pathField = node.remove(Names.PATH);
9096
String path = XContentMapValues.nodeStringValue(pathField, null);
9197
if (path == null) {
92-
throw new MapperParsingException("The [path] property must be specified.");
98+
throw new MapperParsingException("The [path] property must be specified for field [" + name + "].");
9399
}
94100
return builder.path(path);
95101
}

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,8 @@ private void checkCompatibility(MappedFieldType existingFieldType, MappedFieldTy
105105

106106
/** Returns the field for the given field */
107107
public MappedFieldType get(String field) {
108-
String resolvedField = aliasToConcreteName.get(field);
109-
return resolvedField == null
110-
? fullNameToFieldType.get(field)
111-
: fullNameToFieldType.get(resolvedField);
108+
String resolvedField = aliasToConcreteName.getOrDefault(field, field);
109+
return fullNameToFieldType.get(resolvedField);
112110
}
113111

114112
/**

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

+5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ public static void collect(Mapper mapper, Collection<ObjectMapper> objectMappers
3838
fieldMappers.add((FieldMapper)mapper);
3939
} else if (mapper instanceof FieldAliasMapper) {
4040
fieldAliasMappers.add((FieldAliasMapper) mapper);
41+
} else {
42+
throw new IllegalStateException("Unrecognized mapper type [" +
43+
mapper.getClass().getSimpleName() + "].");
4144
}
45+
46+
4247
for (Mapper child : mapper) {
4348
collect(child, objectMappers, fieldMappers, fieldAliasMappers);
4449
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void testParsingWithMissingPath() throws IOException {
7272
.endObject());
7373
MapperParsingException exception = expectThrows(MapperParsingException.class,
7474
() -> parser.parse("type", new CompressedXContent(mapping)));
75-
assertEquals("The [path] property must be specified.", exception.getMessage());
75+
assertEquals("The [path] property must be specified for field [alias-field].", exception.getMessage());
7676
}
7777

7878
public void testParsingWithExtraArgument() throws IOException {

0 commit comments

Comments
 (0)