@@ -24,15 +24,16 @@ def get_es_index(conf: DatasourceConf):
2424 es_client = get_es_connect (conf )
2525 indices = es_client .cat .indices (format = "json" )
2626 res = []
27- for idx in indices :
28- index_name = idx .get ('index' )
29- desc = ''
30- # get mapping
31- mapping = es_client .indices .get_mapping (index = index_name )
32- mappings = mapping .get (index_name ).get ("mappings" )
33- if mappings .get ('_meta' ):
34- desc = mappings .get ('_meta' ).get ('description' )
35- res .append ((index_name , desc ))
27+ if indices is not None :
28+ for idx in indices :
29+ index_name = idx .get ('index' )
30+ desc = ''
31+ # get mapping
32+ mapping = es_client .indices .get_mapping (index = index_name )
33+ mappings = mapping .get (index_name ).get ("mappings" )
34+ if mappings .get ('_meta' ):
35+ desc = mappings .get ('_meta' ).get ('description' )
36+ res .append ((index_name , desc ))
3637 return res
3738
3839
@@ -43,17 +44,18 @@ def get_es_fields(conf: DatasourceConf, table_name: str):
4344 mapping = es_client .indices .get_mapping (index = index_name )
4445 properties = mapping .get (index_name ).get ("mappings" ).get ("properties" )
4546 res = []
46- for field , config in properties .items ():
47- field_type = config .get ("type" )
48- desc = ''
49- if config .get ("_meta" ):
50- desc = config .get ("_meta" ).get ('description' )
47+ if properties is not None :
48+ for field , config in properties .items ():
49+ field_type = config .get ("type" )
50+ desc = ''
51+ if config .get ("_meta" ):
52+ desc = config .get ("_meta" ).get ('description' )
5153
52- if field_type :
53- res .append ((field , field_type , desc ))
54- else :
55- # object、nested...
56- res .append ((field , ',' .join (list (config .keys ())), desc ))
54+ if field_type :
55+ res .append ((field , field_type , desc ))
56+ else :
57+ # object、nested...
58+ res .append ((field , ',' .join (list (config .keys ())), desc ))
5759 return res
5860
5961
0 commit comments