1+
12import getpass
23from typing import Dict , List , Any , Optional , Iterable , Tuple
34import elasticsearch
67from tqdm .notebook import tqdm
78import eland as ed
89
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
912import warnings
10- warnings .filterwarnings ("ignore" )
13+ from elastic_transport import SecurityWarning
14+ from urllib3 .exceptions import InsecureRequestWarning
1115
12- from credentials import *
16+ # Reset all filters
17+ warnings .resetwarnings ()
1318
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 *
1424
1525class CogStack (object ):
26+ warnings .warn ("cogstack module is deprecated, use cogstack2 instead." , DeprecationWarning )
1627 """
1728 A class for interacting with Elasticsearch.
1829
@@ -31,22 +42,22 @@ def __init__(self, hosts: List, username: Optional[str] = None, password: Option
3142 self .elastic = elasticsearch .Elasticsearch (hosts = hosts ,
3243 api_key = api_key ,
3344 verify_certs = False ,
34- timeout = timeout )
45+ request_timeout = timeout )
3546
3647
3748 elif api :
3849 api_username , api_password = self ._check_auth_details (username , password )
3950 self .elastic = elasticsearch .Elasticsearch (hosts = hosts ,
4051 api_key = (api_username , api_password ),
4152 verify_certs = False ,
42- timeout = timeout )
53+ request_timeout = timeout )
4354
4455 else :
4556 username , password = self ._check_auth_details (username , password )
4657 self .elastic = elasticsearch .Elasticsearch (hosts = hosts ,
4758 basic_auth = (username , password ),
4859 verify_certs = False ,
49- timeout = timeout )
60+ request_timeout = timeout )
5061
5162
5263 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:
108119 size = es_gen_size ,
109120 request_timeout = request_timeout )
110121 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
112123 for hit in tqdm (docs_generator , total = results ['count' ], desc = "CogStack retrieved..." , disable = not show_progress ):
113124 row = dict ()
114125 row ['_index' ] = hit ['_index' ]
@@ -155,4 +166,3 @@ def list_chunker(user_list: List[Any], n: int) -> List[List[Any]]:
155166
156167def _no_progress_bar (iterable : Iterable , ** kwargs ):
157168 return iterable
158-
0 commit comments