+ public static String generateDocumentMappings(DocumentSchema schema) throws IOException {
+
+ // Adding dynamic template to add fielddata=true to dynamic fields of type "string"
+ // in order to avoid aggregation queries breaking in ESv6.1.2
+ if (dynamicCustomMapping == null) {
+ try {
+ dynamicCustomMapping = IOUtils.toString(new FileInputStream(DYNAMIC_CUSTOM_TEMPALTE_FILE), "UTF-8")
+ .replaceAll("\\s+", "");
+ } catch (IOException e) {
+ throw new IOException(
+ "Dynamic Custom template configuration went wrong! Please check for the correct template file.",
+ e);
+ }
+ }
+
+ // Now, generate the Elastic Search mapping json and return it.
+ StringBuilder sb = new StringBuilder();
+ sb.append("{");
+ // Adding custom mapping which adds fielddata=true to dynamic fields of type "string"
+ sb.append(dynamicCustomMapping != null ? dynamicCustomMapping : "");
+ sb.append("\"properties\": {");
+
+ generateFieldMappings(schema.getFields(), sb);
+
+ sb.append("}");
+ sb.append("}");
+
+ return sb.toString();
+ }