use of com.alibaba.datax.plugin.writer.elasticsearchwriter.ESClient in project plugins by qlangtech.
the class DataXElasticsearchWriter method initialIndex.
/**
* 当增量开始执行前,先需要初始化一下索引实例
*
* @param esSchema
*/
public void initialIndex(ESTableAlias esSchema) {
if (esSchema == null) {
throw new IllegalArgumentException("param esSchema can not be null");
}
IHttpToken token = this.getToken();
/**
******************************************************
* 初始化索引Schema
******************************************************
*/
JSONArray schemaCols = esSchema.getSchemaCols();
ESClient esClient = new ESClient(ESInitialization.create(token.getEndpoint(), token.getAccessKeyId(), token.getAccessKeySecret(), false, 300000, false, false));
try {
esClient.createIndex(this.getIndexName(), this.type, esClient.genMappings(schemaCols, this.type, (columnList) -> {
}), this.settings, false);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
try {
esClient.closeJestClient();
} catch (Throwable e) {
}
}
}
Aggregations