File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed
src/django_elasticsearch_dsl_drf Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change 1+ from django .conf import settings
12from elasticsearch import Elasticsearch
23
4+ __all__ = (
5+ "get_all_indices" ,
6+ "delete_all_indices" ,
7+ )
8+
39
410def get_all_indices (with_protected = False ):
511 """Get all indices.
6-
712 Args:
813 with_protected (bool):
9-
1014 Returns:
1115 list: List of indices.
1216 """
13- es = Elasticsearch ()
14- _indices = es .indices .get_alias ('*' ).items ()
17+ es = Elasticsearch (** settings . ELASTICSEARCH_DSL [ "default" ] )
18+ _indices = es .indices .get_alias (index = "*" ).items ()
1519 if with_protected :
1620 return [_i for _i , _o in _indices ]
1721 else :
18- return [_i for _i , _o in _indices if not _i .startswith ('.' )]
22+ return [_i for _i , _o in _indices if not _i .startswith ("." )]
1923
2024
2125def delete_all_indices (with_protected = False ):
2226 """Delete all indices.
23-
2427 Args:
2528 with_protected (bool):
26-
2729 Returns:
2830 tuple: Tuple of two lists with removed and errored indices.
2931 """
30- es = Elasticsearch ()
32+ es = Elasticsearch (** settings . ELASTICSEARCH_DSL [ "default" ] )
3133 _indices = get_all_indices (with_protected = with_protected )
3234 _ok = []
3335 _fail = []
3436 for _i in _indices :
3537 try :
36- _res = es .indices .delete (_i )
38+ _res = es .indices .delete (index = _i )
3739 except Exception as err :
3840 _fail .append (_i )
39- if _res and isinstance (_res , dict ) and _res .get (' acknowledged' , False ):
41+ if _res and isinstance (_res , dict ) and _res .get (" acknowledged" , False ):
4042 _ok .append (_i )
4143 return _ok , _fail
You can’t perform that action at this time.
0 commit comments