Skip to content

Commit 8e5ba9a

Browse files
authored
Avoid copying the field alias lookup structure unnecessarily. (elastic#39726)
The field alias map is now only copied if a new alias is added, or if an alias definition has changed. This follows the same behavior as we have for concrete field mappings and avoids unnecessary object creation.
1 parent ef18d3f commit 8e5ba9a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,19 @@ public FieldTypeLookup copyAndAddAll(String type,
6868
MappedFieldType fieldType = fieldMapper.fieldType();
6969
MappedFieldType fullNameFieldType = fullName.get(fieldType.name());
7070

71-
if (!Objects.equals(fieldType, fullNameFieldType)) {
71+
if (Objects.equals(fieldType, fullNameFieldType) == false) {
7272
fullName = fullName.copyAndPut(fieldType.name(), fieldType);
7373
}
7474
}
7575

7676
for (FieldAliasMapper fieldAliasMapper : fieldAliasMappers) {
7777
String aliasName = fieldAliasMapper.name();
7878
String path = fieldAliasMapper.path();
79-
aliases = aliases.copyAndPut(aliasName, path);
79+
80+
String existingPath = aliases.get(aliasName);
81+
if (Objects.equals(path, existingPath) == false) {
82+
aliases = aliases.copyAndPut(aliasName, path);
83+
}
8084
}
8185

8286
return new FieldTypeLookup(fullName, aliases);

0 commit comments

Comments
 (0)