public static <T> void saveSchemaIfNeeded(Object conf, ValueWriter<T> schemaWriter, T schema, Log log) { Settings settings = HadoopSettingsManager.loadFrom(conf); if (settings.getIndexAutoCreate()) { RestRepository client = new RestRepository(settings); if (!client.indexExists(false)) { if (schemaWriter == null) { log.warn(String.format("No mapping found [%s] and no schema found; letting Elasticsearch perform auto-mapping...", settings.getResourceWrite())); } else { log.info(String.format("No mapping found [%s], creating one based on given schema", settings.getResourceWrite())); ContentBuilder builder = ContentBuilder.generate(schemaWriter).value(schema).flush(); BytesArray content = ((FastByteArrayOutputStream) builder.content()).bytes(); builder.close(); client.putMapping(content); if (log.isDebugEnabled()) { log.debug(String.format("Creating ES mapping [%s] from schema [%s]", content.toString(), schema)); } } } client.close(); } }
public static <T> void saveSchemaIfNeeded(Object conf, ValueWriter<T> schemaWriter, T schema, Log log) { Settings settings = HadoopSettingsManager.loadFrom(conf); if (settings.getIndexAutoCreate()) { RestRepository client = new RestRepository(settings); if (!client.indexExists(false)) { if (schemaWriter == null) { log.warn(String.format("No mapping found [%s] and no schema found; letting Elasticsearch perform auto-mapping...", settings.getResourceWrite())); } else { log.info(String.format("No mapping found [%s], creating one based on given schema", settings.getResourceWrite())); ContentBuilder builder = ContentBuilder.generate(schemaWriter).value(schema).flush(); BytesArray content = ((FastByteArrayOutputStream) builder.content()).bytes(); builder.close(); client.putMapping(content); if (log.isDebugEnabled()) { log.debug(String.format("Creating ES mapping [%s] from schema [%s]", content.toString(), schema)); } } } client.close(); } }
public static <T> void saveSchemaIfNeeded(Object conf, ValueWriter<T> schemaWriter, T schema, Log log) { Settings settings = HadoopSettingsManager.loadFrom(conf); if (settings.getIndexAutoCreate()) { RestRepository client = new RestRepository(settings); if (!client.indexExists(false)) { if (schemaWriter == null) { log.warn(String.format("No mapping found [%s] and no schema found; letting Elasticsearch perform auto-mapping...", settings.getResourceWrite())); } else { log.info(String.format("No mapping found [%s], creating one based on given schema", settings.getResourceWrite())); ContentBuilder builder = ContentBuilder.generate(schemaWriter).value(schema).flush(); BytesArray content = ((FastByteArrayOutputStream) builder.content()).bytes(); builder.close(); client.putMapping(content); if (log.isDebugEnabled()) { log.debug(String.format("Creating ES mapping [%s] from schema [%s]", content.toString(), schema)); } } } client.close(); } }
public static <T> void saveSchemaIfNeeded(Object conf, ValueWriter<T> schemaWriter, T schema, Log log) { Settings settings = HadoopSettingsManager.loadFrom(conf); if (settings.getIndexAutoCreate()) { RestRepository client = new RestRepository(settings); if (!client.indexExists(false)) { if (schemaWriter == null) { log.warn(String.format("No mapping found [%s] and no schema found; letting Elasticsearch perform auto-mapping...", settings.getResourceWrite())); } else { log.info(String.format("No mapping found [%s], creating one based on given schema", settings.getResourceWrite())); ContentBuilder builder = ContentBuilder.generate(schemaWriter).value(schema).flush(); BytesArray content = ((FastByteArrayOutputStream) builder.content()).bytes(); builder.close(); client.putMapping(content); if (log.isDebugEnabled()) { log.debug(String.format("Creating ES mapping [%s] from schema [%s]", content.toString(), schema)); } } } client.close(); } }