-
Notifications
You must be signed in to change notification settings - Fork 0
/
inites.py
61 lines (49 loc) · 1.75 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
from elasticsearch import Elasticsearch
from pymongo import MongoClient
client = MongoClient("mongodb://172.27.88.132:27017")
db = client["papers"]
collection = db["100pdfs"]
documents = collection.find()
print("connected to mongodb")
es = Elasticsearch()
index_name = "papers_test1" # 替换为您希望使用的索引名称
if not es.indices.exists(index=index_name):
es.indices.create(index=index_name)
mapping = {
"properties": {
"mongo_id": {"type": "keyword"},
"paper_id": {"type": "keyword"},
"tag": {"type": "keyword"},
"date": {"type": "date"},
"ref_paper": {"type": "keyword"},
"conference": {"type": "keyword"},
"keywords": {"type": "keyword"},
"year": {"type": "integer"},
"author": {
"properties": {
"affiliation": {"type": "text"},
"name": {"type": "text"}
}
},
"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.put_mapping(index=index_name, body=mapping, doc_type="_doc", include_type_name=True)
for document in documents:
document.pop("_id") # 移除 _id 字段
es.index(index=index_name, body=document)
print("indexed")