[ELASTIC-18] NullPointerException in ServerProfileBuilder when creating index without datasource field maping Created: 18/Jan/22  Updated: 18/Jan/22

Status: Open
Project: Elasticsearch
Component/s: None
Affects Version/s: 1.0.0
Fix Version/s: None

Type: Bug Priority: Neutral
Reporter: wolf bubenik Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Java 11, Magnolia 6.2.15


Template:
Patch included:
Yes
Acceptance criteria:
[ ]* Index can be created without having edited a field mapping of the index datasource
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled

 Description   

The Index Editor app - tab datasource does not require a link to a field mapping. However, if it is missing the index creation fails with a NullPointerException. Furthermore the ES server fails creating an index if an empty list of mapping fields is sent.

 

Workaround:

Patch method 

buildMappingsFromJcr() of ServerProfileBuilder:

private Map<String, MappingProperties> buildMappingsFromJcr() throws ElasticConfigurationException {
    Map<String, MappingProperties> indexProperties = new HashMap<>();
    if (this.index.getDatasource().getMappedField() != null) {
        MappingProperties properties = new MappingProperties();
        Map<String, TypeSpecification> fieldSpecification = new HashMap<>();

        for (MappingFieldItemConfiguration field : this.index.getDatasource().getMappedField().getFields()) {
            fieldSpecification.put(field.getName(), this.buildSpecification(field));
        }
        if (!fieldSpecification.isEmpty()) {
            properties.setProperties(fieldSpecification);
            indexProperties.put(this.index.getIndexType(), properties);
        }
    }
    return indexProperties;
} 

Generated at Mon Feb 12 01:46:29 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.