from typing import Dict from server import config from server.client.base.client import Client from server.client.base.config import ClientConfig from server.constants import DSP, Service from server.constants.playlists.v0.misc import ElasticPlaylistsVendorsData class ElasticSearchConfig(ClientConfig): """Configuration class for Apollo api client.""" service = Service.ELASTICSEARCH.value uri = config.ELASTICSEARCH_URL class ElasticSearchClient(Client): """Client for sending requests to Apollo api app.""" index = config.ELASTICSEARCH_PLAYLISTS_INDEX doc_type = ElasticPlaylistsVendorsData.DOC_TYPES async def search(self, dsp: DSP, body: Dict, **params): url = f"{self.index}/{self.doc_type[dsp]}/_search" response = await self.send_request(url, body=body, **params) return response.get("hits", {}).get("hits", [])