-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinites.py
64 lines (51 loc) · 1.87 KB
/
inites.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
from elasticsearch import Elasticsearch
from pymongo import MongoClient
client = MongoClient("mongodb://172.27.88.132:27017")
db = client["arxiv"]
collection = db["arxiv_new"]
documents = collection.find()
print("connected to mongodb")
host = "http://172.27.88.132:9200"
es = Elasticsearch(hosts=host)
print(es.ping())
index_name = "arxiv_new" #对于100pdfs:papers,for arxiv: arxiv_new
if es.indices.exists(index=index_name):
es.indices.delete(index=index_name)
mapping = {
"mappings":{
"properties": {
"paper_id": {"type": "keyword"},
"hash_id": {"type": "keyword"},
"tag": {"type": "keyword"},
"date": {"type": "date"},
"authors" :{"type": "text"},
"ref_paper": {"type": "text"},
"conference": {"type": "text"},
"keywords": {"type": "text"},
"categories": {"type": "text"},
"year": {"type": "integer"},
"last_page": {"type": "integer"},
"link": {"type": "keyword"},
"abstract": {"type": "text"},
"title": {"type": "text"},
"volume": {"type": "keyword"},
"update_time": {"type": "date"},
"journal": {"type": "text"},
"issn": {"type": "keyword"},
"first_page": {"type": "integer"},
"publisher": {"type": "text"},
"doi": {"type": "keyword"},
"pdf_address": {"type": "keyword"},
"pics_address": {"type": "keyword"},
"csv_address": {"type": "keyword"},
"table_rendition_address": {"type": "text"}
}
}
}
es.indices.create(index=index_name,body=mapping)
for document in documents:
hash_id = str(document["_id"])
document["hash_id"] = hash_id
document.pop("_id")
es.index(index=index_name, doc_type='_doc', body=document)
print("indexed")