-
Notifications
You must be signed in to change notification settings - Fork 0
/
es.py
executable file
·50 lines (45 loc) · 1.06 KB
/
es.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
#!/usr/bin/env python3
from elasticsearch import Elasticsearch
from elasticsearch import helpers
es = Elasticsearch()
mapping = {
"mappings": {
"properties": {
"ISRC": {
"type": "keyword"
},
"artist": {
"type": "keyword"
},
"date": {
"type": "date",
"format": "yyyy-MM-ddTHH:mm:ss"
},
"list_time": {
"type": "integer"
},
"hour": {
"type": "integer"
},
"day_of_week": {
"type": "integer"
},
"title": {
"type": "keyword"
}
}
}
}
def reset_index():
es.indices.delete(index='deezer', ignore=[404])
es.indices.create(index='deezer', ignore=[400], body=mapping)
def bulk(tracks):
actions = [
{
"_index": "deezer",
"_id": track.id(),
"_source": track.as_es_obj()
}
for track in tracks
]
helpers.bulk(actions=actions, client=es)