{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "292fbf42",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/leozangulo/Library/Python/3.9/lib/python/site-packages/urllib3/__init__.py:35: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020\n",
      "  warnings.warn(\n"
     ]
    }
   ],
   "source": [
    "from elasticsearch import Elasticsearch\n",
    "from elasticsearch.helpers import bulk\n",
    "from elasticsearch import exceptions as es_exceptions\n",
    "from langchain.embeddings import SentenceTransformerEmbeddings\n",
    "import pandas as pd\n",
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "84e039f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "try:\n",
    "    esuser = \"<USERNAME>\"\n",
    "except KeyError:\n",
    "    esuser = input(\"Please enter your Elasticsearch user name (hit enter): \")\n",
    "try:\n",
    "    espassword = \"<PASSWORD>\"\n",
    "except KeyError:\n",
    "    espassword = getpass.getpass(\"Please enter your Elasticsearch password (hit enter): \")\n",
    "try:\n",
    "    eshost = \"<ELASTIC_URL>\"\n",
    "except KeyError:\n",
    "    eshost = input(\"Please enter your Elasticsearch hostname (hit enter): \")\n",
    "try:\n",
    "    esport = \"XXXX\"\n",
    "except KeyError:\n",
    "    esport = input(\"Please enter your Elasticsearch port number (hit enter): \")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "cb563197",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'22:B8:75:5A:05:3F:6D:7D:D7:43:CB:07:63:41:0B:5B:B0:AC:2F:C9:9F:BF:8C:CE:3C:D4:42:5F:B0:92:E4:A9'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "es_ssl_fingerprint = !openssl s_client -connect $eshost:$esport  -showcerts </dev/null 2>/dev/null | openssl x509 -fingerprint -sha256 -noout -in /dev/stdin\n",
    "es_ssl_fingerprint = es_ssl_fingerprint[0].split(\"=\")[1]\n",
    "es_ssl_fingerprint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "aa36655c",
   "metadata": {},
   "outputs": [],
   "source": [
    "elastic_client = Elasticsearch([f\"https://{esuser}:{espassword}@{eshost}:{esport}\"],\n",
    "                              basic_auth=(esuser, espassword),\n",
    "                              request_timeout=None,\n",
    "                              ssl_assert_fingerprint=es_ssl_fingerprint)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "88d064ea-3ec8-49e4-b0ca-1c8c77b7def7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Conexión exitosa. Info del clúster:\n",
      "{'name': 'm-1.63ae1f09-63d0-42c1-a834-11658d84d119.b3580ea2cd7943f795db3d4b2f063fc7.c5kmhkid0ujpmrucb800.databases.appdomain.cloud', 'cluster_name': '63ae1f09-63d0-42c1-a834-11658d84d119', 'cluster_uuid': '1OewP8bXSO2Y48FwiRaqeg', 'version': {'number': '8.15.0', 'build_flavor': 'default', 'build_type': 'tar', 'build_hash': '1a77947f34deddb41af25e6f0ddb8e830159c179', 'build_date': '2024-08-05T10:05:34.233336849Z', 'build_snapshot': False, 'lucene_version': '9.11.1', 'minimum_wire_compatibility_version': '7.17.0', 'minimum_index_compatibility_version': '7.0.0'}, 'tagline': 'You Know, for Search'}\n"
     ]
    }
   ],
   "source": [
    "# Verificar que la conexión este creada\n",
    "try:\n",
    "    info = elastic_client.info()\n",
    "    print(\"Conexión exitosa. Info del clúster:\")\n",
    "    print(info)\n",
    "except es_exceptions.AuthenticationException as e:\n",
    "    print(\"Error de autenticación:\", e.info)\n",
    "except es_exceptions.ConnectionError as e:\n",
    "    print(\"Error de conexión:\", e.info)\n",
    "except es_exceptions.AuthorizationException as e:\n",
    "    print(\"Error de autorización:\", e.info)\n",
    "except es_exceptions.TransportError as e:\n",
    "    print(\"Error general de transporte:\", e.info)\n",
    "except Exception as e:\n",
    "    print(\"Otro error:\", str(e))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f856c004-8571-4e83-9a2f-1366c1f5b021",
   "metadata": {},
   "source": [
    "## Selección del modelo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "2cf5eb6c",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/var/folders/h_/w76hwqrd6kv3q8ps8cm4_y980000gn/T/ipykernel_87367/2620494856.py:1: LangChainDeprecationWarning: The class `HuggingFaceEmbeddings` was deprecated in LangChain 0.2.2 and will be removed in 1.0. An updated version of the class exists in the :class:`~langchain-huggingface package and should be used instead. To use it run `pip install -U :class:`~langchain-huggingface` and import as `from :class:`~langchain_huggingface import HuggingFaceEmbeddings``.\n",
      "  emb_func = SentenceTransformerEmbeddings(model_name=\"all-MiniLM-L6-v2\")\n",
      "/Users/leozangulo/Library/Python/3.9/lib/python/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    }
   ],
   "source": [
    "emb_func = SentenceTransformerEmbeddings(model_name=\"all-MiniLM-L6-v2\")\n",
    "dims = emb_func.client.get_sentence_embedding_dimension()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "7fdf69ae",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ObjectApiResponse({'acknowledged': True, 'shards_acknowledged': True, 'index': 'test_nds_v2'})"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Creación del índice y del esquema\n",
    "index_name = \"test_nds_v2\"\n",
    "\n",
    "mapping = {\n",
    "        \"properties\": {\n",
    "                \"text\": {\n",
    "                        \"type\": \"text\"\n",
    "                    },\n",
    "                \"embedding\": {\n",
    "                        \"type\": \"dense_vector\",\n",
    "                        \"dims\": dims,\n",
    "                        \"index\": True,\n",
    "                        \"similarity\": \"l2_norm\"\n",
    "                    }\n",
    "            }\n",
    "    }\n",
    "if elastic_client.indices.exists(index=index_name):\n",
    "    elastic_client.indices.delete(index=index_name)\n",
    "    \n",
    "elastic_client.indices.create(index=index_name, mappings=mapping)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0b58d667",
   "metadata": {},
   "source": [
    "## Definición de documentos"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e498f6cf",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Seleccionar todos los .txt\n",
    "scl = []\n",
    "for file in os.listdir(\"./\"):\n",
    "    if file.endswith(\".txt\"):\n",
    "        print(os.path.join(file))\n",
    "        scl.append(file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "a78ea9a7-29f3-4094-a5f3-feb9035ece14",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>resumen</th>\n",
       "      <th>Compositor</th>\n",
       "      <th>Pregunta</th>\n",
       "      <th>Respuesta</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Tema: Mozart, Pregunta: ¿Dónde nació Mozart?, ...</td>\n",
       "      <td>Mozart</td>\n",
       "      <td>¿Dónde nació Mozart?</td>\n",
       "      <td>Mozart nació en Salzburgo, que en su época era...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Tema: Mozart, Pregunta: ¿A qué edad empezó a c...</td>\n",
       "      <td>Mozart</td>\n",
       "      <td>¿A qué edad empezó a componer?</td>\n",
       "      <td>Comenzó a componer desde los 5 años, escribien...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Tema: Mozart, Pregunta: ¿Cuál es su nombre com...</td>\n",
       "      <td>Mozart</td>\n",
       "      <td>¿Cuál es su nombre completo?</td>\n",
       "      <td>Su nombre completo era Johannes Chrysostomus W...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Tema: Mozart, Pregunta: ¿Qué significa “Amadeu...</td>\n",
       "      <td>Mozart</td>\n",
       "      <td>¿Qué significa “Amadeus”?</td>\n",
       "      <td>Significa 'amado de Dios' en latín, aunque tam...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Tema: Mozart, Pregunta: ¿Qué famosa ópera comp...</td>\n",
       "      <td>Mozart</td>\n",
       "      <td>¿Qué famosa ópera compuso en 1786?</td>\n",
       "      <td>Compuso 'Las bodas de Fígaro' (Le nozze di Fig...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Tema: Mozart, Pregunta: ¿Cuál es su ópera cons...</td>\n",
       "      <td>Mozart</td>\n",
       "      <td>¿Cuál es su ópera considerada la más oscura y ...</td>\n",
       "      <td>Sin duda 'Don Giovanni', que mezcla comedia y ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Tema: Mozart, Pregunta: ¿Qué obra dejó inconcl...</td>\n",
       "      <td>Mozart</td>\n",
       "      <td>¿Qué obra dejó inconclusa al morir?</td>\n",
       "      <td>Su famoso Réquiem en Re menor, que estaba comp...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Tema: Mozart, Pregunta: ¿Quién terminó su Réqu...</td>\n",
       "      <td>Mozart</td>\n",
       "      <td>¿Quién terminó su Réquiem?</td>\n",
       "      <td>Fue su alumno Franz Xaver Süssmayr, quien comp...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>Tema: Mozart, Pregunta: ¿En qué ciudad murió M...</td>\n",
       "      <td>Mozart</td>\n",
       "      <td>¿En qué ciudad murió Mozart?</td>\n",
       "      <td>Murió en Viena, la capital de Austria, donde p...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>Tema: Mozart, Pregunta: ¿A qué edad murió?, Re...</td>\n",
       "      <td>Mozart</td>\n",
       "      <td>¿A qué edad murió?</td>\n",
       "      <td>Murió muy joven, a los 35 años, dejando más de...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                             resumen Compositor  \\\n",
       "0  Tema: Mozart, Pregunta: ¿Dónde nació Mozart?, ...     Mozart   \n",
       "1  Tema: Mozart, Pregunta: ¿A qué edad empezó a c...     Mozart   \n",
       "2  Tema: Mozart, Pregunta: ¿Cuál es su nombre com...     Mozart   \n",
       "3  Tema: Mozart, Pregunta: ¿Qué significa “Amadeu...     Mozart   \n",
       "4  Tema: Mozart, Pregunta: ¿Qué famosa ópera comp...     Mozart   \n",
       "5  Tema: Mozart, Pregunta: ¿Cuál es su ópera cons...     Mozart   \n",
       "6  Tema: Mozart, Pregunta: ¿Qué obra dejó inconcl...     Mozart   \n",
       "7  Tema: Mozart, Pregunta: ¿Quién terminó su Réqu...     Mozart   \n",
       "8  Tema: Mozart, Pregunta: ¿En qué ciudad murió M...     Mozart   \n",
       "9  Tema: Mozart, Pregunta: ¿A qué edad murió?, Re...     Mozart   \n",
       "\n",
       "                                            Pregunta  \\\n",
       "0                               ¿Dónde nació Mozart?   \n",
       "1                     ¿A qué edad empezó a componer?   \n",
       "2                       ¿Cuál es su nombre completo?   \n",
       "3                          ¿Qué significa “Amadeus”?   \n",
       "4                 ¿Qué famosa ópera compuso en 1786?   \n",
       "5  ¿Cuál es su ópera considerada la más oscura y ...   \n",
       "6                ¿Qué obra dejó inconclusa al morir?   \n",
       "7                         ¿Quién terminó su Réquiem?   \n",
       "8                       ¿En qué ciudad murió Mozart?   \n",
       "9                                 ¿A qué edad murió?   \n",
       "\n",
       "                                           Respuesta  \n",
       "0  Mozart nació en Salzburgo, que en su época era...  \n",
       "1  Comenzó a componer desde los 5 años, escribien...  \n",
       "2  Su nombre completo era Johannes Chrysostomus W...  \n",
       "3  Significa 'amado de Dios' en latín, aunque tam...  \n",
       "4  Compuso 'Las bodas de Fígaro' (Le nozze di Fig...  \n",
       "5  Sin duda 'Don Giovanni', que mezcla comedia y ...  \n",
       "6  Su famoso Réquiem en Re menor, que estaba comp...  \n",
       "7  Fue su alumno Franz Xaver Süssmayr, quien comp...  \n",
       "8  Murió en Viena, la capital de Austria, donde p...  \n",
       "9  Murió muy joven, a los 35 años, dejando más de...  "
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "documents_filename = \"./qna.csv\"\n",
    "documents = pd.read_csv(documents_filename, header=0)\n",
    "c = documents['Compositor']\n",
    "p = documents['Pregunta']\n",
    "r = documents['Respuesta']\n",
    "documents['resumen'] = 'Tema: '+c+', Pregunta: '+p+', Respuesta: '+r\n",
    "\n",
    "\n",
    "cols = documents.columns.tolist()\n",
    "cols = ['resumen'] + [col for col in cols if col != 'resumen']\n",
    "documents = documents[cols]\n",
    "\n",
    "documents[:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "6e1c4696",
   "metadata": {},
   "outputs": [],
   "source": [
    "texts = documents.resumen.tolist()\n",
    "embedded_docs = emb_func.embed_documents(texts)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "2f52cc78",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "test_nds_v2\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "ObjectApiResponse({'_shards': {'total': 2, 'successful': 2, 'failed': 0}})"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Guardar los documentos en la DB\n",
    "for i, (text, vector) in enumerate(zip(texts, embedded_docs)):\n",
    "    document_l = {\"embedding\": vector, 'text': text}\n",
    "    elastic_client.index(index=index_name, document=document_l)\n",
    "    \n",
    "\n",
    "elastic_client.indices.refresh(index=index_name)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "7110e733-5e33-4a07-908b-790a9a67ad25",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "📊 El índice '.ent-search-actastic-oauth_access_tokens_v2' tiene 50 documentos.\n"
     ]
    }
   ],
   "source": [
    "# Mostrar cantidad de indices\n",
    "try:\n",
    "    response = elastic_client.count(index=\"test_nds_v2\")\n",
    "    total_docs = response['count']\n",
    "    print(f\"📊 El índice '{indice}' tiene {total_docs} documentos.\")\n",
    "except Exception as e:\n",
    "    print(\"❌ Error al obtener el conteo:\", e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1a460246-f99d-46f4-bdf1-d8dd7a20ddfd",
   "metadata": {},
   "outputs": [],
   "source": [
    "#document_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "9332a307-e2f6-4d7d-a094-38547e85373b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "📊 El índice '.ent-search-actastic-oauth_access_tokens_v2' tiene 0 documentos.\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    response = elastic_client.count(index=\"test_nds_v2\")\n",
    "    total_docs = response['count']\n",
    "    print(f\"📊 El índice '{indice}' tiene {total_docs} documentos.\")\n",
    "except Exception as e:\n",
    "    print(\"❌ Error al obtener el conteo:\", e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "19a46065-a48b-425e-8a89-cb0089748220",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "- .ent-search-actastic-workplace_search_accounts_v16\n",
      "- .ent-search-actastic-workplace_search_search_groups_v4-name-unique-constraint\n",
      "- .ent-search-actastic-crawler2_robots_txts\n",
      "- .ent-search-actastic-workplace_search_pre_content_sources_v3\n",
      "- .ent-search-actastic-crawler_crawl_requests_v7\n",
      "- .ent-search-esqueues-me_queue_v1_process_crawl2\n",
      "- .ent-search-actastic-reindex_jobs_v3\n",
      "- .ent-search-actastic-workplace_search_role_mappings_v8\n",
      "- .kibana_8.15.0_001\n",
      "- .ent-search-actastic-search_relevance_suggestion_update_process_v1\n",
      "- .apm-custom-link\n",
      "- .ent-search-actastic-connectors_jobs_v5\n",
      "- .ml-annotations-000001\n",
      "- .ent-search-actastic-workplace_search_content_sources_v23\n",
      "- .internal.alerts-observability.uptime.alerts-default-000001\n",
      "- .ent-search-actastic-users_v7-auth_source-elasticsearch_username-unique-constraint\n",
      "- .ent-search-actastic-crawler_process_crawls\n",
      "- .apm-source-map\n",
      "- .ent-search-actastic-users_v7-email-unique-constraint\n",
      "- .ent-search-actastic-crawler2_configurations_v2-index_name-unique-constraint\n",
      "- .slo-observability.summary-v3.3.temp\n",
      "- .ent-search-actastic-app_search_api_tokens_v3-authentication_token-unique-constraint\n",
      "- .ent-search-actastic-workplace_search_organizations_v17\n",
      "- .ent-search-actastic-search_indices_v1\n",
      "- .ent-search-actastic-app_search_crawler_content_url_metadata\n",
      "- .elastic-connectors-sync-jobs-v1\n",
      "- .ent-search-esqueues-me_queue_v1_process_crawl\n",
      "- .kibana_task_manager_8.15.0_001\n",
      "- .ent-search-actastic-crawler2_content_metadata-configuration_oid-content_hash-unique-constraint\n",
      "- .ent-search-esqueues-me_worker_v1\n",
      "- .ent-search-actastic-engines_v26\n",
      "- .ml-notifications-000002\n",
      "- .internal.alerts-transform.health.alerts-default-000001\n",
      "- .ent-search-actastic-app_search_api_token_engines\n",
      "- .internal.alerts-observability.apm.alerts-default-000001\n",
      "- .ent-search-actastic-crawler2_domains-configuration_oid-name-unique-constraint\n",
      "- .ent-search-actastic-crawler2_configurations_v2\n",
      "- .ent-search-actastic-crawler2_content_metadata\n",
      "- .ent-search-esqueues-me_queue_v1_mailer\n",
      "- .kibana_security_solution_8.15.0_001\n",
      "- .internal.alerts-security.alerts-default-000001\n",
      "- .ent-search-actastic-workplace_search_pre_content_sources_v3-context-workplace_search_account_id-service_type-unique-constraint\n",
      "- .ent-search-actastic-secret_keeper_secrets\n",
      "- .ent-search-actastic-crawler_domains_v6\n",
      "- .internal.alerts-observability.logs.alerts-default-000001\n",
      "- .ent-search-actastic-oauth_access_tokens_v2-token-unique-constraint\n",
      "- .ent-search-actastic-crawler2_process_crawls\n",
      "- .ent-search-actastic-crawler2_content_url_metadata\n",
      "- .ent-search-actastic-app_search_role_mapping_engines_v4\n",
      "- .ent-search-actastic-oauth_applications_v2\n",
      "- .ent-search-actastic-oauth_applications_v2-uid-unique-constraint\n",
      "- .ent-search-actastic-search_relevance_suggestions-document_position_id-unique-constraint\n",
      "- .kibana-observability-ai-assistant-kb-000001\n",
      "- .ent-search-esqueues-me_queue_v1_engine_destroyer\n",
      "- .ent-search-actastic-app_search_crawler_content_metadata-content_hash-engine_oid-unique-constraint\n",
      "- .ent-search-actastic-app_search_document_positions_v3\n",
      "- .ent-search-db-lock-20200304\n",
      "- .ent-search-actastic-oauth_access_grants_v2\n",
      "- .kibana_alerting_cases_8.15.0_001\n",
      "- .slo-observability.sli-v3.3\n",
      "- .internal.alerts-ml.anomaly-detection.alerts-default-000001\n",
      "- .ent-search-actastic-synonyms\n",
      "- .kibana_security_session_1\n",
      "- .internal.alerts-observability.slo.alerts-default-000001\n",
      "- .ent-search-actastic-crawler_domains_v6-engine_oid-name-unique-constraint\n",
      "- .ent-search-actastic-workplace_search_content_source_user_identities_v4\n",
      "- .internal.alerts-observability.metrics.alerts-default-000001\n",
      "- .kibana_ingest_8.15.0_001\n",
      "- .ent-search-actastic-workplace_search_api_tokens\n",
      "- .ent-search-actastic-telemetry_status_v3\n",
      "- .internal.alerts-stack.alerts-default-000001\n",
      "- .ent-search-actastic-togo_migrations_v1\n",
      "- .apm-agent-configuration\n",
      "- .ent-search-actastic-app_search_crawler_content_metadata\n",
      "- .kibana-observability-ai-assistant-conversations-000001\n",
      "- .ent-search-actastic-crawler2_domains\n",
      "- .ent-search-actastic-search_relevance_suggestions\n",
      "- .internal.alerts-observability.threshold.alerts-default-000001\n",
      "- .ent-search-actastic-users_v7\n",
      "- .ent-search-actastic-workplace_search_search_groups_v4\n",
      "- .ent-search-actastic-app_search_invitations_v3\n",
      "- .ent-search-actastic-engines_v26-loco_moco_account_id-slug-unique-constraint\n",
      "- .internal.alerts-default.alerts-default-000001\n",
      "- .internal.alerts-ml.anomaly-detection-health.alerts-default-000001\n",
      "- .ent-search-actastic-crawler2_crawl_requests_v2\n",
      "- .ent-search-actastic-app_search_document_position_queries_v4\n",
      "- .ent-search-actastic-oauth_access_tokens_v2-refresh_token-unique-constraint\n",
      "- .ent-search-actastic-crawler2_extraction_rules\n",
      "- .ent-search-actastic-app_search_api_tokens_v3\n",
      "- .slo-observability.summary-v3.3\n",
      "- .ent-search-actastic-workplace_search_invitations_v3\n",
      "- .kibana_analytics_8.15.0_001\n",
      "- .ent-search-actastic-workplace_search_accounts_v16-user_oid-unique-constraint\n",
      "- .ent-search-actastic-crawler_robots_txts_v3\n",
      "- test_nds_v2\n",
      "- test_nds\n",
      "- .ent-search-actastic-app_search_accounts_v11\n",
      "- .ent-search-actastic-app_search_role_mappings_v5\n",
      "- .ent-search-actastic-oauth_access_tokens_v2\n"
     ]
    }
   ],
   "source": [
    "# Ver cuantos indices hay\n",
    "indices = elastic_client.indices.get_alias(index=\"*\").keys()\n",
    "for indice in indices:\n",
    "    print(\"-\", indice)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
