-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_collector.py
44 lines (36 loc) · 1.01 KB
/
data_collector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# coding: utf-8
from elasticsearch import Elasticsearch
from elasticsearch import helpers
class DataCollectorWithKafka:
pass
class DataCollectorWithElasticSearch:
def __init__(self, hosts: str, index: str, doc_type: str):
self.hosts = hosts
self.index = index
self.doc_type = doc_type
self.es_client = Elasticsearch(hosts=self.hosts)
def _search(self, payload: dict):
return self.es_client.search(
index=self.index,
doc_type=self.doc_type,
body=payload
)["hits"]["hits"]
def _scan(
self,
payload: dict,
size: int = 10000,
scroll: str = "5m",
timeout: int = "1m"
):
return helpers.scan(
client=self.es_client,
index=self.index,
doc_type=self.doc_type,
query=payload,
scroll=scroll,
size=size,
timeout=timeout
)
def get_log(self):
# todo
pass