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
1
2
from elasticsearch import Elasticsearch
2
3
4
+ __all__ = (
5
+ "get_all_indices" ,
6
+ "delete_all_indices" ,
7
+ )
8
+
3
9
4
10
def get_all_indices (with_protected = False ):
5
11
"""Get all indices.
6
-
7
12
Args:
8
13
with_protected (bool):
9
-
10
14
Returns:
11
15
list: List of indices.
12
16
"""
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 ()
15
19
if with_protected :
16
20
return [_i for _i , _o in _indices ]
17
21
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 ("." )]
19
23
20
24
21
25
def delete_all_indices (with_protected = False ):
22
26
"""Delete all indices.
23
-
24
27
Args:
25
28
with_protected (bool):
26
-
27
29
Returns:
28
30
tuple: Tuple of two lists with removed and errored indices.
29
31
"""
30
- es = Elasticsearch ()
32
+ es = Elasticsearch (** settings . ELASTICSEARCH_DSL [ "default" ] )
31
33
_indices = get_all_indices (with_protected = with_protected )
32
34
_ok = []
33
35
_fail = []
34
36
for _i in _indices :
35
37
try :
36
- _res = es .indices .delete (_i )
38
+ _res = es .indices .delete (index = _i )
37
39
except Exception as err :
38
40
_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 ):
40
42
_ok .append (_i )
41
43
return _ok , _fail
You can’t perform that action at this time.
0 commit comments