Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
crawler
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
backend
crawler
Commits
d48a436a
Commit
d48a436a
authored
Dec 21, 2020
by
litaolemo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
bc21ff8a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
49 deletions
+49
-49
revise_data_from_es.py
write_data_into_es/revise_data_from_es.py
+49
-49
No files found.
write_data_into_es/revise_data_from_es.py
View file @
d48a436a
...
@@ -19,15 +19,15 @@ hosts = '172.16.31.17'
...
@@ -19,15 +19,15 @@ hosts = '172.16.31.17'
port
=
9000
port
=
9000
es2
=
elasticsearch
.
Elasticsearch
(
hosts
=
hosts
,
port
=
port
)
es2
=
elasticsearch
.
Elasticsearch
(
hosts
=
hosts
,
port
=
port
)
#
es7 = e7.Elasticsearch(hosts="172.16.52.27", port=9200,http_auth=("elastic","gengmei!@#"))
es7
=
e7
.
Elasticsearch
(
hosts
=
"172.16.52.27"
,
port
=
9200
,
http_auth
=
(
"elastic"
,
"gengmei!@#"
))
es7
=
e7
.
Elasticsearch
(
hosts
=
"172.16.31.17"
,
port
=
9000
)
#
es7 = e7.Elasticsearch(hosts="172.16.31.17", port=9000)
target_index
=
'gm-dbmw-doctor-read'
target_index
=
'gm-dbmw-doctor-read'
target_type
=
'doctor'
target_type
=
'doctor'
from_index
=
'gm-dbmw-doctor-read'
from_index
=
'gm-dbmw-doctor-read'
from_type
=
'doc'
from_type
=
'
_
doc'
bulk_all_body
=
''
bulk_all_body
=
''
...
@@ -47,49 +47,49 @@ es7_re = es7.search(index=target_index, doc_type=target_type,
...
@@ -47,49 +47,49 @@ es7_re = es7.search(index=target_index, doc_type=target_type,
print
(
es7_re
)
print
(
es7_re
)
#
#
# q3_total = es2_re['hits']['total']
# q3_total = es2_re['hits']['total']
#
write_into_scan = scan(client=es2,
write_into_scan
=
scan
(
client
=
es2
,
#
query=search_body,
query
=
search_body
,
#
index=target_index,
index
=
target_index
,
#
doc_type=target_type,
doc_type
=
target_type
,
#
scroll='5m',
scroll
=
'5m'
,
#
request_timeout=100
request_timeout
=
100
#
)
)
#
#
count = 0
count
=
0
#
for one_scan in write_into_scan:
for
one_scan
in
write_into_scan
:
#
count = count + 1
count
=
count
+
1
#
line = one_scan['_source']
line
=
one_scan
[
'_source'
]
#
doc_id = one_scan['_id']
doc_id
=
one_scan
[
'_id'
]
#
try:
try
:
#
if line['facevideo_is_assistant'] == 1:
if
line
[
'facevideo_is_assistant'
]
==
1
:
#
line['facevideo_is_assistant'] = True
line
[
'facevideo_is_assistant'
]
=
True
#
else:
else
:
#
line['facevideo_is_assistant'] = False
line
[
'facevideo_is_assistant'
]
=
False
#
except:
except
:
#
pass
pass
#
#
bulk_head = '{"index": {"_id":"%s"}}' % doc_id
bulk_head
=
'{"index": {"_id":"
%
s"}}'
%
doc_id
#
data_str = json.dumps(line, ensure_ascii=False)
data_str
=
json
.
dumps
(
line
,
ensure_ascii
=
False
)
#
#
bulk_one_body = bulk_head + '\n' + data_str + '\n'
bulk_one_body
=
bulk_head
+
'
\n
'
+
data_str
+
'
\n
'
#
# print(bulk_one_body)
# print(bulk_one_body)
#
bulk_all_body += bulk_one_body
bulk_all_body
+=
bulk_one_body
#
# break
# break
#
if count%500 == 0:
if
count
%
500
==
0
:
#
#
eror_dic=es7.bulk(index=target_index,
eror_dic
=
es7
.
bulk
(
index
=
target_index
,
#
body=bulk_all_body, request_timeout=200)
body
=
bulk_all_body
,
request_timeout
=
200
)
#
bulk_all_body=''
bulk_all_body
=
''
#
if eror_dic['errors'] is True:
if
eror_dic
[
'errors'
]
is
True
:
#
print(eror_dic['items'])
print
(
eror_dic
[
'items'
])
#
print(bulk_all_body)
print
(
bulk_all_body
)
#
print(count)
print
(
count
)
#
#
if bulk_all_body != '':
if
bulk_all_body
!=
''
:
#
eror_dic = es7.bulk(body=bulk_all_body,
eror_dic
=
es7
.
bulk
(
body
=
bulk_all_body
,
#
index=target_index,
index
=
target_index
,
#
request_timeout=200)
request_timeout
=
200
)
#
if eror_dic['errors'] is True:
if
eror_dic
[
'errors'
]
is
True
:
#
print(eror_dic)
print
(
eror_dic
)
#
#
bulk_all_body = ''
bulk_all_body
=
''
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