1
+
1
2
import getpass
2
3
from typing import Dict , List , Any , Optional , Iterable , Tuple
3
4
import elasticsearch
6
7
from tqdm .notebook import tqdm
7
8
import eland as ed
8
9
10
+ # Suppress warnings related to security in Elasticsearch
11
+ # This is necessary to avoid warnings about insecure connections when using self-signed certificates or HTTP connections
9
12
import warnings
10
- warnings .filterwarnings ("ignore" )
13
+ from elastic_transport import SecurityWarning
14
+ from urllib3 .exceptions import InsecureRequestWarning
11
15
12
- from credentials import *
16
+ # Reset all filters
17
+ warnings .resetwarnings ()
13
18
19
+ warnings .filterwarnings ("module" , category = DeprecationWarning , module = "cogstack" )
20
+ warnings .filterwarnings ('ignore' , category = SecurityWarning )
21
+ warnings .filterwarnings ('ignore' , category = InsecureRequestWarning )
22
+
23
+ from credentials import *
14
24
15
25
class CogStack (object ):
26
+ warnings .warn ("cogstack module is deprecated, use cogstack2 instead." , DeprecationWarning )
16
27
"""
17
28
A class for interacting with Elasticsearch.
18
29
@@ -31,22 +42,22 @@ def __init__(self, hosts: List, username: Optional[str] = None, password: Option
31
42
self .elastic = elasticsearch .Elasticsearch (hosts = hosts ,
32
43
api_key = api_key ,
33
44
verify_certs = False ,
34
- timeout = timeout )
45
+ request_timeout = timeout )
35
46
36
47
37
48
elif api :
38
49
api_username , api_password = self ._check_auth_details (username , password )
39
50
self .elastic = elasticsearch .Elasticsearch (hosts = hosts ,
40
51
api_key = (api_username , api_password ),
41
52
verify_certs = False ,
42
- timeout = timeout )
53
+ request_timeout = timeout )
43
54
44
55
else :
45
56
username , password = self ._check_auth_details (username , password )
46
57
self .elastic = elasticsearch .Elasticsearch (hosts = hosts ,
47
58
basic_auth = (username , password ),
48
59
verify_certs = False ,
49
- timeout = timeout )
60
+ request_timeout = timeout )
50
61
51
62
52
63
def _check_auth_details (self , username = None , password = None ) -> Tuple [str , str ]:
@@ -108,7 +119,7 @@ def cogstack2df(self, query: Dict, index: str, column_headers=None, es_gen_size:
108
119
size = es_gen_size ,
109
120
request_timeout = request_timeout )
110
121
temp_results = []
111
- results = self .elastic .count (index = index , query = query ['query' ], request_timeout = 300 ) # type: ignore
122
+ results = self .elastic .count (index = index , query = query ['query' ]) # type: ignore
112
123
for hit in tqdm (docs_generator , total = results ['count' ], desc = "CogStack retrieved..." , disable = not show_progress ):
113
124
row = dict ()
114
125
row ['_index' ] = hit ['_index' ]
@@ -155,4 +166,3 @@ def list_chunker(user_list: List[Any], n: int) -> List[List[Any]]:
155
166
156
167
def _no_progress_bar (iterable : Iterable , ** kwargs ):
157
168
return iterable
158
-
0 commit comments