refactor(backend): integrate elasticsearch service into search_persons function
LocationBasedServices/smartguide/pipeline/head This commit looks good

This commit is contained in:
Steven Tischer
2026-05-28 16:38:35 +02:00
parent 4a37c8d041
commit 28c79e113a
+6 -18
View File
@@ -20,6 +20,7 @@ import json
from . import schema
from . import model
from . import config
from .integrations import elasticsearch
logger = logging.getLogger(__name__)
topic_cache_filename: str = "topic_hierarchy_cache.json"
@@ -200,11 +201,6 @@ def count_topic_hierarchy(topic_names: List[str]) -> dict:
def search_persons(author_id: Optional[str] = None, query: Optional[str] = None,
include: Optional[set[str]] = None) -> model.PersonSearchResult:
headers = {
"Authorization": f"ApiKey {config.settings.elasticsearch_api_key}",
"Content-Type": "application/json"
}
if author_id:
query_field = "_id"
query_value = author_id
@@ -214,19 +210,11 @@ def search_persons(author_id: Optional[str] = None, query: Optional[str] = None,
else:
return "Either author_id or query must be provided"
payload = {
"query": {
"query_string": {
"default_field": query_field,
"query": query_value
}
}
}
with httpx.Client() as client:
response = client.post(config.settings.elasticsearch_url + '/openalex-authors/_search', json=payload, headers=headers)
response.raise_for_status()
data = response.json()
data = elasticsearch.search(
index="openalex-authors",
query_field=query_field,
query_value=query_value
)
include_set = {tag.strip().lower() for tag in include} if include else set()
persons = []