mirror of
https://github.com/didi/KnowStreaming.git
synced 2025-12-24 20:22:12 +08:00
修复自动创建ES索引模版失败问题
This commit is contained in:
@@ -392,10 +392,7 @@ public class ESOpClient {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public boolean templateExist(String indexTemplateName){
|
||||||
* 创建索引模板
|
|
||||||
*/
|
|
||||||
public boolean createIndexTemplateIfNotExist(String indexTemplateName, String config) {
|
|
||||||
ESClient esClient = null;
|
ESClient esClient = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -410,6 +407,29 @@ public class ESOpClient {
|
|||||||
if (null != templateConfig) {
|
if (null != templateConfig) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.warn( "method=templateExist||indexTemplateName={}||msg=exception!",
|
||||||
|
indexTemplateName, e);
|
||||||
|
} finally {
|
||||||
|
if (esClient != null) {
|
||||||
|
this.returnESClientToPool(esClient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建索引模板
|
||||||
|
*/
|
||||||
|
public boolean createIndexTemplateIfNotExist(String indexTemplateName, String config) {
|
||||||
|
ESClient esClient = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
esClient = this.getESClientFromPool();
|
||||||
|
|
||||||
|
//存在模板就返回,不存在就创建
|
||||||
|
if(templateExist(indexTemplateName)){return true;}
|
||||||
|
|
||||||
// 创建新的模板
|
// 创建新的模板
|
||||||
ESIndicesPutTemplateResponse response = esClient.admin().indices().preparePutTemplate( indexTemplateName )
|
ESIndicesPutTemplateResponse response = esClient.admin().indices().preparePutTemplate( indexTemplateName )
|
||||||
@@ -417,8 +437,7 @@ public class ESOpClient {
|
|||||||
|
|
||||||
return response.getAcknowledged();
|
return response.getAcknowledged();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.warn(
|
LOGGER.warn( "method=createIndexTemplateIfNotExist||indexTemplateName={}||config={}||msg=exception!",
|
||||||
"class=ESOpClient||method=createIndexTemplateIfNotExist||indexTemplateName={}||config={}||msg=exception!",
|
|
||||||
indexTemplateName, config, e
|
indexTemplateName, config, e
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user