Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
search_tips
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
rank
search_tips
Commits
6fdcd970
Commit
6fdcd970
authored
Jun 06, 2019
by
lixiaofang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
best_answer
parent
365ee846
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
0 deletions
+58
-0
trans2es_mapping2es.py
trans2es/management/commands/trans2es_mapping2es.py
+58
-0
No files found.
trans2es/management/commands/trans2es_mapping2es.py
0 → 100644
View file @
6fdcd970
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from
django.conf
import
settings
from
django.core.management.base
import
BaseCommand
,
CommandError
import
traceback
import
logging
from
libs.es
import
ESPerform
from
trans2es.type_info
import
get_type_info_map
,
TypeInfo
class
Command
(
BaseCommand
):
args
=
''
help
=
'dump mapping to elasticsearch'
from
optparse
import
make_option
option_list
=
BaseCommand
.
option_list
+
(
make_option
(
'-t'
,
'--type'
,
dest
=
'type'
,
help
=
'type name to dump data to elasticsearch'
,
metavar
=
'TYPE'
,
default
=
''
),
make_option
(
'-T'
,
'--indices_template'
,
dest
=
'indices_template'
,
help
=
'index template name to dump data to elasticsearch'
,
metavar
=
'TYPE'
,
default
=
''
),
make_option
(
'-i'
,
'--index-prefix'
,
dest
=
'index_prefix'
,
help
=
'index name to dump data to elasticsearch'
,
metavar
=
'INDEX_PREFIX'
),
make_option
(
'-p'
,
'--parallel'
,
dest
=
'parallel'
,
help
=
'parallel process count'
,
metavar
=
'PARALLEL'
),
make_option
(
'-s'
,
'--pks'
,
dest
=
'pks'
,
help
=
'specify sync pks, comma separated'
,
metavar
=
'PKS'
,
default
=
''
),
make_option
(
'--streaming-slicing'
,
dest
=
'streaming_slicing'
,
action
=
'store_true'
,
default
=
True
),
make_option
(
'--no-streaming-slicing'
,
dest
=
'streaming_slicing'
,
action
=
'store_false'
,
default
=
True
),
)
def
handle
(
self
,
*
args
,
**
options
):
try
:
es_cli
=
ESPerform
.
get_cli
()
type_name_list
=
get_type_info_map
()
.
keys
()
for
type_name
in
type_name_list
:
if
len
(
options
[
"type"
]):
if
options
[
"type"
]
==
"all"
or
type_name
==
options
[
"type"
]:
official_index_name
=
ESPerform
.
get_official_index_name
(
type_name
)
index_exists
=
es_cli
.
indices
.
exists
(
official_index_name
)
if
not
index_exists
:
logging
.
info
(
"begin create [
%
s] index!"
%
type_name
)
ESPerform
.
create_index
(
es_cli
,
type_name
)
logging
.
info
(
"begin create [
%
s] mapping!"
%
type_name
)
ESPerform
.
put_index_mapping
(
es_cli
,
type_name
)
if
len
(
options
[
"indices_template"
]):
template_file_name
=
options
[
"indices_template"
]
if
ESPerform
.
put_indices_template
(
es_cli
=
es_cli
,
template_file_name
=
template_file_name
,
template_name
=
template_file_name
):
logging
.
info
(
"put indices template suc!"
)
else
:
logging
.
error
(
"put indices template err!"
)
except
:
logging
.
error
(
"catch exception,err_msg:
%
s"
%
traceback
.
format_exc
())
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