from typing import List
from typing import Dict
from typing import Any


def get_logging_query(
    model_name: str,
    docs: List[str],
    search_keys: Dict[str, Any]
) -> Dict[str, Any]:
    """
    The process to extract features from Elasticsearch involves sending what is known
    as the "logging query". The result of the loggin query is the values, for a given
    search query, of each feature as defined in feature set.

    Args
    ----
      model_name: str
          Each Kubeflow run receives a model_name so it's possible to discern each
          experiment. This value is used to store different models on Elasticsearch.
      docs: List[str]
          List containing several documents (skus for instance) to be inserted in the
          query so it's possible to send several requests in just one request.
      search_keys: Dict[str, Any]
          Those are the keys that describe the search context. It can contain
          data such as the region of customers, their favorite brands, their average
          purchasing ticket and so on.

    Returns
    -------
      log_query: Dict[str, Any]
          Query to be sent against Elasticsearch in order to find the values of each
          feature as defined in featureset.
    """
    log_query = {
        "query": {
            "bool": {
                "filter": [
                    {
                        "terms": {
                            "_id": ""
                        }
                    }
                ],
                "should": [
                    {
                        "sltr": {
                            "_name": "logged_featureset",
                            "featureset": model_name,
                            "params": {}
                        }
                    }
                ]
            }
        },
        "_source": ['_id'],
        "ext": {
            "ltr_log": {
                "log_specs": {
                    "name": "main",
                    "named_query": "logged_featureset"
                }
            }
        }
    }
    log_query['query']['bool']['filter'][0]['terms']['_id'] = docs
    log_query['query']['bool']['should'][0]['sltr']['params'] = search_keys
    return log_query