-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcv19_index.py
50 lines (39 loc) · 1.11 KB
/
cv19_index.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
import string
import sys
import getopt
import os.path
import json
from elasticsearch import Elasticsearch
INDEXNAME = 'cv19index'
DOCTYPE = 'cv19doc'
VERBOSE = True
FILEIDS = "docids1.txt"
FILEDOCS = "docs1.json"
es = Elasticsearch([{'host':'localhost','port':9200}])
infileid = open(FILEIDS,'r')
infiledocs = open(FILEDOCS,'r')
validlist = list()
stringa = infileid.readline()[0:-1]
validlist.append(stringa)
while stringa is not "":
stringa = infileid.readline()[0:-1]
validlist.append(stringa)
ndoc = 0
for doc in infiledocs:
if len(doc) > 0:
ndoc += 1
cv19_doc = json.loads(doc)
this_id = str(cv19_doc["cord_uid"])
if this_id is not None and this_id in validlist:
if VERBOSE:
print(FILEDOCS,ndoc,this_id,'...',end='')
res = es.index(index=INDEXNAME,
doc_type=DOCTYPE,
id=this_id,
body=cv19_doc)
if VERBOSE:
print("added")
if VERBOSE:
print("done")
if VERBOSE:
print("done")