diff --git a/src/main/java/com/graphaware/module/es/mapping/AdvancedMapping.java b/src/main/java/com/graphaware/module/es/mapping/AdvancedMapping.java index 121064b..e63448b 100644 --- a/src/main/java/com/graphaware/module/es/mapping/AdvancedMapping.java +++ b/src/main/java/com/graphaware/module/es/mapping/AdvancedMapping.java @@ -47,27 +47,48 @@ public class AdvancedMapping extends DefaultMapping { private static final Map NODE_MAPPINGS = new HashMap<>(); private static final Map RELATIONSHIP_MAPPINGS = new HashMap<>(); + private static Map.Entry entry(String key, Object value) { + return new HashMap.SimpleEntry<>(key, value); + } + + @SafeVarargs + private static Map map(Map.Entry ...entries) { + Map m = new HashMap<>(entries.length); + for (Map.Entry entry : entries) { + m.put(entry.getKey(), entry.getValue()); + } + return m; + } + static { - Map rawField = new HashMap<>(); - rawField.put("type", "string"); - rawField.put("index", "not_analyzed"); - rawField.put("include_in_all", false); - - Map labelOrTypePropertyFields = new HashMap<>(); - labelOrTypePropertyFields.put("raw", rawField); - - Map labelOrTypeProperty = new HashMap<>(); - labelOrTypeProperty.put("type", "string"); - labelOrTypeProperty.put("fields", labelOrTypePropertyFields); - - Map nodeProperties = new HashMap<>(); - nodeProperties.put(LABELS_FIELD, labelOrTypeProperty); - NODE_MAPPINGS.put("properties", nodeProperties); - - Map relationshipProperties = new HashMap<>(); - relationshipProperties.put(RELATIONSHIP_FIELD, labelOrTypeProperty); - RELATIONSHIP_MAPPINGS.put("properties", relationshipProperties); + List> dynamicTemplates = Collections.singletonList(map( + entry("any_field", map( + entry("match_mapping_type", "*"), + entry("mapping", map( + entry("type", "{dynamic_type}"), + entry("ignore_malformed", true) + )) + )) + )); + + Map labelOrTypeProperty = map( + entry("type", "string"), + entry("fields", map( + entry("raw", map( + entry("type", "string"), + entry("index", "not_analyzed"), + entry("include_in_all", false) + )) + )) + ); + + NODE_MAPPINGS.put("properties", map(entry(LABELS_FIELD, labelOrTypeProperty))); + NODE_MAPPINGS.put("dynamic_templates", dynamicTemplates); + NODE_MAPPINGS.put("dynamic", true); + + RELATIONSHIP_MAPPINGS.put("properties", map(entry(RELATIONSHIP_FIELD, labelOrTypeProperty))); + RELATIONSHIP_MAPPINGS.put("dynamic_templates", dynamicTemplates); + RELATIONSHIP_MAPPINGS.put("dynamic", true); } @Override