-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateIndex.py
More file actions
36 lines (30 loc) · 1.09 KB
/
createIndex.py
File metadata and controls
36 lines (30 loc) · 1.09 KB
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
from elasticsearch import Elasticsearch, helpers
from elasticsearch_dsl import Index
import json,re
# import queries
client = Elasticsearch(HOST="http://localhost",PORT=9200)
INDEX = 'male-cricketers-data'
index = Index(INDEX,using=client)
res = index.create()
print (res)
with open('Corpus/cricketers.json','r') as f:
cricketers = json.loads(f.read())
for i in range(len(cricketers)):
y = json.dumps(cricketers[i])
z=json.loads(y)
print(z)
e={
"nameEn" : z["Name_En"],
"nameSi" : z["Name_si"],
"fullName" : z["Full Name"],
"country" : z["Country"],
"dateOfBirth": z["Date of Birth"],
"playingRole": z["Playing Role"],
"battingStyle":z["Batting Style"],
"bowlingStyle": z["Bowling Style"],
"teams":z["Teams"],
"profile":z["Profile"]
}
print(e)
res=client.index(index=INDEX,id=i,body=e)
print (res)