Files
2024-04-29 16:01:03 +02:00

96 lines
2.5 KiB
Python

from elasticsearch import Elasticsearch
import pandas as pd
import sys
es = Elasticsearch({'host':'inse.nes.uni-due.de', 'port': 443, 'path_prefix':'elastic', 'scheme':'https'}, basic_auth=('elastic', 'RLldUaJgbGeoqd3KCX3p'), request_timeout=60, max_retries=5, retry_on_timeout=True)
if not es.ping():
print("Elastic is Down!")
sys.exit()
else:
print("Elastic is Up!")
df = pd.DataFrame(columns=['title', 'faculty', 'institute', 'chair'])
ids = []
query = {
"match_all": {}
}
docs = es.search(index="merged_publication_person_ude", query=query, size=1000, sort=[{"id.keyword": "desc"}])
current_max = len(docs.get('hits').get('hits')) - 1
# get ids from current query
for hit in docs.get('hits').get('hits'):
ids.append(hit.get('_id'))
# while loop until all results are done
while (current_max > 0):
current_last_sort = docs.get('hits').get('hits')[current_max].get('sort')
# get next result-page
docs = es.search(index="merged_publication_person_ude", query=query, size=1000, search_after=current_last_sort, sort=[{"id.keyword": "desc"}])
current_max = len(docs.get('hits').get('hits')) - 1
for hit in docs.get('hits').get('hits'):
ids.append(hit.get('_id'))
number = str(len(ids))
print(number)
counter = 1
for id in ids:
print(" - " + id + " (" + str(counter) + "/" + number + ")")
counter += 1
# get publication
query = {
"match": {
"id": id
}
}
source = es.search(index="merged_publication_person_ude", query=query, size=1).get("hits").get("hits")[0].get("_source")
title = source["title"]
authors = source["authors"]
for author in authors:
chair = ""
faculty = ""
institute = ""
try:
chair = author["chair"]
except:
pass
try:
faculty = author["faculty"]
except:
pass
try:
institute = author["institute"]
except:
pass
if (chair == None):
chair = ""
if (faculty == None):
faculty = ""
if (institute == None):
institute = ""
if (chair == "" and faculty == "" and institute == ""):
continue
new_row = {'title': title, 'faculty': faculty, 'institute': institute, 'chair': chair}
df.loc[len(df)] = new_row
num_rows = df.shape[0]
print("Number of rows:", num_rows)
df.to_csv('pubs_title_orgs_2.csv', index=False, sep=';', encoding='utf-8')
print("Finished")