Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
崔为之
elp
Commits
187a55b6
Commit
187a55b6
authored
Nov 21, 2023
by
崔为之
💪🏽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update project
parent
663fbfb2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
16 deletions
+40
-16
application/utils/elasticsearch/elasticsearch.py
application/utils/elasticsearch/elasticsearch.py
+40
-16
No files found.
application/utils/elasticsearch/elasticsearch.py
View file @
187a55b6
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
# @Email : StudentCWZ@outlook.com
# @Email : StudentCWZ@outlook.com
# @Date : 2023/10/28 12:19
# @Date : 2023/10/28 12:19
# @File : elasticsearch.py
# @File : elasticsearch.py
# @Description :
# @Description :
A utility class to interact with Elasticsearch.
"""
"""
import
datetime
import
datetime
...
@@ -15,16 +15,24 @@ import datetime
...
@@ -15,16 +15,24 @@ import datetime
from
application.extensions.init_elasticsearch
import
es
from
application.extensions.init_elasticsearch
import
es
import
datetime
from
application.extensions.init_elasticsearch
import
es
class
ElasticsearchUtil
:
class
ElasticsearchUtil
:
@
classmethod
@
classmethod
def
dsl
(
cls
,
_start
:
str
,
_end
:
str
,
size
=
5000
)
->
dict
:
def
dsl
(
cls
,
_start
:
str
,
_end
:
str
,
size
=
5000
)
->
dict
:
"""
"""
Setting dsl
Constructs a DSL (Domain Specific Language) query for Elasticsearch.
Args:
_start (str): Start time.
_end (str): End time.
size (int, optional): Number of data results. Defaults to 5000.
:param _start: start time
Returns:
:param _end: end time
dict: The DSL query.
:param size: data number
:return: dsl
"""
"""
_dsl
=
{
_dsl
=
{
"size"
:
size
,
"size"
:
size
,
...
@@ -61,27 +69,43 @@ class ElasticsearchUtil:
...
@@ -61,27 +69,43 @@ class ElasticsearchUtil:
@
classmethod
@
classmethod
def
search
(
cls
,
_index
:
str
,
_dsl
:
dict
,
_scroll
=
"5m"
)
->
dict
:
def
search
(
cls
,
_index
:
str
,
_dsl
:
dict
,
_scroll
=
"5m"
)
->
dict
:
"""
"""
Search
data
Search
es data in Elasticsearch.
:param _index: index name
Args:
:param _dsl: dsl
_index (str): Index name.
:param _scroll: scroll time
_dsl (dict): DSL query.
:return: data after search
_scroll (str, optional): Scroll time. Defaults to "5m".
Returns:
dict: Data after the search.
"""
"""
return
es
.
search
(
index
=
_index
,
scroll
=
_scroll
,
body
=
_dsl
)
return
es
.
search
(
index
=
_index
,
scroll
=
_scroll
,
body
=
_dsl
)
@
classmethod
@
classmethod
def
scroll_search
(
cls
,
_id
,
_scroll
=
"5m"
)
->
dict
:
def
scroll_search
(
cls
,
_id
,
_scroll
=
"5m"
)
->
dict
:
"""
"""
Search data
Searches data in Elasticsearch using scroll.
Args:
_id (str): Scroll ID.
_scroll (str, optional): Scroll time. Defaults to "5m".
:param _id: scroll id
Returns:
:param _scroll: scroll time
dict: Data after the search by scroll.
:return: data after search by scroll
"""
"""
return
es
.
scroll
(
scroll_id
=
_id
,
scroll
=
_scroll
,
request_timeout
=
30
)
return
es
.
scroll
(
scroll_id
=
_id
,
scroll
=
_scroll
,
request_timeout
=
30
)
@
classmethod
@
classmethod
def
insert_data
(
cls
,
index
:
str
,
doc_type
:
str
,
data
:
dict
)
->
None
:
def
insert_data
(
cls
,
index
:
str
,
doc_type
:
str
,
data
:
dict
)
->
None
:
# 插入数据
"""
Inserts data into Elasticsearch.
Args:
index (str): Index name.
doc_type (str): Document type.
data (dict): Data to be inserted.
Returns:
None
"""
es
.
index
(
index
=
index
,
doc_type
=
doc_type
,
body
=
data
)
es
.
index
(
index
=
index
,
doc_type
=
doc_type
,
body
=
data
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment