Skip to content

Commit 902be7e

Browse files
authored
Merge pull request #22 from vitaliyok/feature/access_cogstack
Updated ES search functions and authentication
2 parents 3e5ec5d + 1899508 commit 902be7e

File tree

6 files changed

+1026
-12
lines changed

6 files changed

+1026
-12
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ data/cogstack_search_results/
1111

1212
# Default environments
1313
venv
14+
15+
# python cache folder
16+
__pycache__

cogstack.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
import getpass
23
from typing import Dict, List, Any, Optional, Iterable, Tuple
34
import elasticsearch
@@ -6,13 +7,23 @@
67
from tqdm.notebook import tqdm
78
import 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
912
import 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

1525
class 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

156167
def _no_progress_bar(iterable: Iterable, **kwargs):
157168
return iterable
158-

0 commit comments

Comments
 (0)