def METHOD_NAME(config):
    p = parse_url(config.registry.settings["elasticsearch.url"])
    qs = urllib.parse.parse_qs(p.query)
    kwargs = {
        "hosts": [urllib.parse.urlunparse((p.scheme, p.netloc) + ("",) * 4)],
        "verify_certs": True,
        "ca_certs": certifi.where(),
        "timeout": 2,
        "retry_on_timeout": False,
        "serializer": serializer.serializer,
        "max_retries": 1,
    }
    aws_auth = bool(qs.get("aws_auth", False))
    if aws_auth:
        aws_region = qs.get("region", ["us-east-1"])[0]
        kwargs["connection_class"] = elasticsearch.RequestsHttpConnection
        kwargs["http_auth"] = requests_aws4auth.AWS4Auth(
            config.registry.settings["aws.key_id"],
            config.registry.settings["aws.secret_key"],
            aws_region,
            "es",
        )
    config.registry["elasticsearch.client"] = elasticsearch.Elasticsearch(**kwargs)
    config.registry["elasticsearch.index"] = p.path.strip("/")
    config.registry["elasticsearch.shards"] = int(qs.get("shards", ["1"])[0])
    config.registry["elasticsearch.replicas"] = int(qs.get("replicas", ["0"])[0])
    config.add_request_method(es, name="es", reify=True)
    from warehouse.search.tasks import reindex
    config.add_periodic_task(crontab(minute=0, hour=6), reindex)