feat(backend): add centralized elasticsearch query function

This commit is contained in:
Steven Tischer
2026-05-28 16:37:24 +02:00
parent 982e01a26a
commit 4a37c8d041
2 changed files with 33 additions and 0 deletions
@@ -0,0 +1,33 @@
from typing import Any, Optional
import httpx
from .. import config
def search(
index: str,
query_field: str,
query_value: str
) -> dict[str, Any]:
headers = {
"Authorization": f"ApiKey {config.settings.elasticsearch_api_key}",
"Content-Type": "application/json"
}
payload = {
"query": {
"query_string": {
"default_field": query_field,
"query": query_value
}
}
}
with httpx.Client() as client:
response = client.post(
f"{config.settings.elasticsearch_url}/{index}/_search",
json=payload,
headers=headers
)
response.raise_for_status()
return response.json()