Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
physical
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
physical
Commits
cea5c194
Commit
cea5c194
authored
Nov 22, 2018
by
段英荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify
parent
484e67c9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
3 deletions
+38
-3
es.py
libs/es.py
+33
-0
type_info.py
trans2es/type_info.py
+5
-3
No files found.
libs/es.py
View file @
cea5c194
...
@@ -8,6 +8,7 @@ import os.path
...
@@ -8,6 +8,7 @@ import os.path
import
re
import
re
import
json
import
json
from
elasticsearch
import
Elasticsearch
from
elasticsearch
import
Elasticsearch
import
elasticsearch.helpers
class
ESPerform
(
object
):
class
ESPerform
(
object
):
...
@@ -116,3 +117,34 @@ class ESPerform(object):
...
@@ -116,3 +117,34 @@ class ESPerform(object):
except
:
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
False
return
False
@classmethod
def
es_helpers_bulk
(
cls
,
es_cli
,
data_list
,
sub_index_name
,
auto_create_index
=
False
,
doc_type
=
"_doc"
):
try
:
assert
(
es_cli
is
not
None
)
official_index_name
=
cls
.
get_official_index_name
(
sub_index_name
)
index_exists
=
es_cli
.
indices
.
exists
(
official_index_name
)
if
not
index_exists
:
if
not
auto_create_index
:
logging
.
error
(
"index:
%
s is not existing,bulk data error!"
%
official_index_name
)
return
False
else
:
cls
.
create_index
(
es_cli
,
sub_index_name
)
cls
.
put_index_mapping
(
es_cli
,
sub_index_name
)
bulk_actions
=
[]
for
data
in
data_list
:
bulk_actions
.
append
({
'_op_type'
:
'index'
,
'_index'
:
official_index_name
,
'_type'
:
doc_type
,
'_id'
:
data
[
'id'
],
'_source'
:
data
,
})
elasticsearch
.
helpers
.
bulk
(
es_cli
,
bulk_actions
)
return
True
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
return
False
\ No newline at end of file
trans2es/type_info.py
View file @
cea5c194
...
@@ -7,6 +7,7 @@ import logging
...
@@ -7,6 +7,7 @@ import logging
import
traceback
import
traceback
import
django.db.models
import
django.db.models
from
django.conf
import
settings
from
django.conf
import
settings
from
libs.es
import
ESPerform
import
elasticsearch
import
elasticsearch
import
elasticsearch.helpers
import
elasticsearch.helpers
import
sys
import
sys
...
@@ -196,10 +197,11 @@ class TypeInfo(object):
...
@@ -196,10 +197,11 @@ class TypeInfo(object):
stage_2_time
=
time
.
time
()
stage_2_time
=
time
.
time
()
es_result
=
self
.
elasticsearch_bulk_insert_data
(
es_result
=
ESPerform
.
es_helpers_bulk
(
sub_index_name
=
sub_index_name
,
es_cli
=
es
,
data_list
=
data_list
,
data_list
=
data_list
,
es
=
es
,
sub_index_name
=
sub_index_name
,
auto_create_index
=
True
)
)
stage_3_time
=
time
.
time
()
stage_3_time
=
time
.
time
()
...
...
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