-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_insert.py
68 lines (62 loc) · 1.63 KB
/
create_insert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# encoding: utf-8
from index_utils import *
import json
import pdb
mapping = '''
{
"settings" : {
"index": {
"number_of_shards" : 3,
"number_of_replicas" : 2
}
},
"mappings":{
"sources": {
"properties": {
"adult":{
"type": "boolean"
},
"original_language":{
"type": "keyword",
"index": "true"
},
"original_title":{
"type": "text",
"index": "true"
},
"overview":{
"type": "text",
"index": "true"
},
"popularity":{
"type": "float"
},
"runtime":{
"type": "short"
},
"tagline":{
"type": "text",
"index": "true"
},
"vote_average":{
"type": "float"
}
}
}
}
}'''
def pre_process(source):
for id, item in source.items():
try:
del item['release_date']
except KeyError:
pass
return source
if __name__ == "__main__":
# 创建`index`
# create_index('tmdb', mapping)
# 插入数据
movieDict = json.load(open('/data/home/liusunan/es/ltr_test/ranklib_test/tmdb.json'))
print('{}load data finish{}'.foramt('*'*10))
movieDict = pre_process(movieDict)
data2es('tmdb', 'sources', movieDict)