diff --git a/service/src/main/inse/integrations/__init__.py b/service/src/main/inse/integrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/service/src/main/inse/integrations/elasticsearch.py b/service/src/main/inse/integrations/elasticsearch.py new file mode 100644 index 00000000..e3ad986f --- /dev/null +++ b/service/src/main/inse/integrations/elasticsearch.py @@ -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()