Skip to content

Commit

Permalink
Stop providing mappings/settings for data indices
Browse files Browse the repository at this point in the history
  • Loading branch information
seanstory committed Dec 2, 2024
1 parent a92df70 commit 507cbbf
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 732 deletions.
2 changes: 1 addition & 1 deletion connectors/cli/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import asyncio
from collections import OrderedDict

from connectors.es import DEFAULT_LANGUAGE
from connectors.es.cli_client import CLIClient
from connectors.es.settings import DEFAULT_LANGUAGE
from connectors.protocol import (
CONCRETE_CONNECTORS_INDEX,
CONCRETE_JOBS_INDEX,
Expand Down
4 changes: 2 additions & 2 deletions connectors/connectors_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from connectors.cli.index import Index
from connectors.cli.job import Job
from connectors.config import _default_config
from connectors.es.settings import Settings
from connectors.es import DEFAULT_LANGUAGE

__all__ = ["main"]

Expand Down Expand Up @@ -159,7 +159,7 @@ def list_connectors(obj):
click.echo(e)


language_keys = [*Settings().language_data.keys()]
language_keys = [DEFAULT_LANGUAGE]


# Support blank values for languge
Expand Down
4 changes: 3 additions & 1 deletion connectors/es/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
from connectors.es.client import ESClient # NOQA
from connectors.es.document import ESDocument, InvalidDocumentSourceError # NOQA
from connectors.es.index import ESIndex # NOQA
from connectors.es.settings import DEFAULT_LANGUAGE, Mappings # NOQA

TIMESTAMP_FIELD = "_timestamp"
DEFAULT_LANGUAGE = "en"
96 changes: 1 addition & 95 deletions connectors/es/management_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
)
from elasticsearch.helpers import async_scan

from connectors.es import TIMESTAMP_FIELD
from connectors.es.client import ESClient
from connectors.es.settings import TIMESTAMP_FIELD, Mappings, Settings
from connectors.logger import logger


Expand Down Expand Up @@ -51,107 +51,13 @@ async def ensure_exists(self, indices=None):
logger.debug(f"Created index {index}")

async def create_content_index(self, search_index_name, language_code):
settings = Settings(language_code=language_code, analysis_icu=False).to_hash()
mappings = Mappings.default_text_fields_mappings(is_connectors_index=True)

return await self._retrier.execute_with_retry(
partial(
self.client.indices.create,
index=search_index_name,
mappings=mappings,
settings=settings,
)
)

async def ensure_content_index_mappings(self, index_name, index, desired_mappings):
# open = Match open, non-hidden indices. Also matches any non-hidden data stream.
# Content indices are always non-hidden.

existing_mappings = index.get("mappings", {})
if len(existing_mappings) == 0:
if desired_mappings:
logger.info(
"Index %s has no mappings or it's empty. Adding mappings...", index
)
try:
await self._retrier.execute_with_retry(
partial(
self.client.indices.put_mapping,
index=index_name,
dynamic=desired_mappings.get("dynamic", False),
dynamic_templates=desired_mappings.get(
"dynamic_templates", []
),
properties=desired_mappings.get("properties", {}),
)
)
logger.info("Successfully added mappings for index %s", index_name)
except Exception as e:
logger.warning(
f"Could not create mappings for index {index}, encountered error {e}"
)
else:
logger.info(
"Index %s has no mappings but no mappings are provided, skipping mappings creation"
)
else:
logger.debug(
"Index %s already has mappings, skipping mappings creation", index_name
)

async def ensure_content_index_settings(
self, index_name, index, language_code=None
):
existing_settings = index.get("settings", {})
settings = Settings(language_code=language_code, analysis_icu=False).to_hash()

if "analysis" not in existing_settings.get("index", {}):
logger.info(
f"Index {index_name} has no settings or it's empty. Adding settings..."
)

# Open index, update settings, close index
try:
if self.serverless:
await self._retrier.execute_with_retry(
partial(
self.client.perform_request,
"PUT",
f"/{index_name}/_settings?reopen=true",
body=settings,
headers={
"accept": "application/json",
"content-type": "application/json",
},
)
)
else:
await self._retrier.execute_with_retry(
partial(self.client.indices.close, index=index_name)
)

await self._retrier.execute_with_retry(
partial(
self.client.indices.put_settings,
index=index_name,
body=settings,
)
)

await self._retrier.execute_with_retry(
partial(self.client.indices.open, index=index_name)
)

logger.info(f"Successfully added settings for index {index_name}")
except Exception as e:
logger.warning(
f"Could not create settings for index {index_name}, encountered error {e}"
)
else:
logger.debug(
f"Index {index_name} already has settings, skipping settings creation"
)

async def ensure_ingest_pipeline_exists(
self, pipeline_id, version, description, processors
):
Expand Down
Loading

0 comments on commit 507cbbf

Please sign in to comment.