This repository has been archived by the owner on Oct 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#40 elasticsearch controller class added
- Loading branch information
1 parent
bc76798
commit 76d943d
Showing
4 changed files
with
81 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from elasticsearch import Elasticsearch | ||
|
||
|
||
class ElasticController: | ||
def __init__(self, | ||
cloud_id: str, | ||
user_id: str, | ||
user_pw: str, | ||
index_name: str): | ||
self.elastic = Elasticsearch(cloud_id, http_auth={user_id, user_pw}) | ||
self.index = index_name | ||
|
||
def read(self, | ||
query: dict, | ||
highlight: dict = None): | ||
""" | ||
:param query: | ||
:param highlight: | ||
''' | ||
>>> # Example input parameter | ||
>>> query = { | ||
>>> 'match_phrase': { | ||
>>> 'eg': { | ||
>>> 'query': query, | ||
>>> 'analyzer': 'nori' | ||
>>> } | ||
>>> } | ||
>>> } | ||
>>> highlight = { | ||
>>> 'fields': { | ||
>>> 'eg': { | ||
>>> 'type': 'plain', | ||
>>> 'fragment_size': 15, | ||
>>> 'number_of_fragments': 2, | ||
>>> 'fragmenter': 'span' | ||
>>> } | ||
>>> } | ||
>>> } | ||
''' | ||
:return: | ||
""" | ||
return self.elastic.search(index=self.index, query=query, highlight=highlight) | ||
|
||
def write(self, | ||
info, | ||
bulk: bool): | ||
""" | ||
:param bulk: | ||
:param info: | ||
:return: | ||
""" | ||
|
||
if bulk: | ||
# TODO: Bulk upload 구현. | ||
self.elastic.bulk(index=self.index, doc_type='_doc') | ||
else: | ||
return self.elastic.index(index=self.index, doc_type='_doc', document=info) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters