//采集es元数据
/*Connection saveConn =null;
CloseableHttpClient httpclient=null;
httpclient = HttpClientBuilder.create().build();
String httpUrl ="http://localhost:9200/_all";
log.debug("采集ElasticsearchURL :"+httpUrl);
HttpGet httpget = new HttpGet(httpUrl);
HttpResponse res = httpclient.execute(httpget);
String result = EntityUtils.toString(res.getEntity());// 返回json格式:
log.debug("采集ElasticsearchMapData= :"+result);
JSONObject esIndexsData = JSON.parseObject(result);
Iterator indexs = esIndexsData.keySet().iterator();
while (indexs.hasNext()) {
String indexName =indexs.next();
if(esIndexsData.get(indexName) instanceof JSONObject ){
JSONObject mappingInfo =esIndexsData.getJSONObject(indexName).getJSONObject("mappings");
if (mappingInfo==null){
continue;
}
//提取typeName 遍历字段定义
Iterator types=mappingInfo.keySet().iterator();
//提取表的后半部分
while(types.hasNext()){
String subfix =types.next();
String TABLE_NAME =indexName+"-"+ subfix;
String TABLE_TYPE ="TABLE";
String OWNER = indexName;
String CREATE_DATE ="2019-03-06 00:00:00";
String DESCRIPTION="";
//解析字段信息
JSONObject fieldsPro=mappingInfo.getJSONObject(subfix).getJSONObject("properties");
//解析_meta信息
JSONObject metaInfo =mappingInfo.getJSONObject(subfix).getJSONObject("_meta");
if(fieldsPro==null){
continue;
}
Iterator fieldKeys =fieldsPro.keySet().iterator();
int position=0;
while(fieldKeys.hasNext()){
position++;
String COLUMN_NAME = fieldKeys.next();
JSONObject fieldInfo =fieldsPro.getJSONObject(COLUMN_NAME);
String ORDINAL_POSITION = position+"";
String COLUMN_DEFAULT ="";
String IS_NULLABLE = "";
String isIndex="Y";
if("false".equalsIgnoreCase(fieldInfo.getString("index"))){
isIndex="N";
}
String DATA_TYPE = fieldInfo.getString("type")==null?"":fieldInfo.getString("type");
//从fields对象取字段长度
String CHARACTER_MAXIMUM_LENGTH = "";
JSONObject fields =fieldInfo.getJSONObject("fields");
if(fields!=null && fields.getJSONObject("keyword")!=null){
if(fields.getJSONObject("keyword").getString("ignore_above")!=null){
CHARACTER_MAXIMUM_LENGTH=fields.getJSONObject("keyword").getString("ignore_above");
}
}
String NUMERIC_PRECISION = "";
String NUMERIC_SCALE = "";
String fieldDesc = "";
String metaData="";
JSONObject fileMeta=null;
if(metaInfo!=null){
fileMeta= metaInfo.getJSONObject(COLUMN_NAME);
}
fieldDesc =fileMeta!=null ?fileMeta.getString("字段名"):"";
metaData =fileMeta!=null ?fileMeta.getString("备注"):"";
// 处理type='nested'字段信息
}
}
}
}*/
获取elasticsearch的元数据
关注
打赏
