This repository has been archived by the owner on Nov 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(es): remove duplicates, change oddrn creation (#226)
* fix: remove duplicates * chore: update es generator
- Loading branch information
Showing
15 changed files
with
262 additions
and
552 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from typing import Optional | ||
|
||
from elasticsearch import Elasticsearch | ||
|
||
from odd_collector.domain.plugin import ElasticsearchPlugin | ||
|
||
|
||
class Client: | ||
def __init__(self, config: ElasticsearchPlugin): | ||
self._es = Elasticsearch( | ||
hosts=[f"{config.host}:{config.port}"], | ||
basic_auth=(config.username, config.password.get_secret_value()), | ||
verify_certs=config.verify_certs, | ||
ca_certs=config.ca_certs, | ||
) | ||
|
||
def get_indices(self, index: Optional[str] = None, h=None) -> list: | ||
return self._es.cat.indices(format="json", index=index, h=h).body | ||
|
||
def get_mapping(self, index_name: Optional[str] = None) -> dict: | ||
return self._es.indices.get_mapping(index=index_name).body | ||
|
||
def get_index_settings(self, index_name: str) -> dict: | ||
return self._es.indices.get_settings(index=index_name).body | ||
|
||
def get_data_streams(self, name: Optional[str] = None) -> dict: | ||
response = self._es.indices.get_data_stream(name=name) | ||
return response["data_streams"] | ||
|
||
def get_index_template(self, template_name: str) -> list[dict]: | ||
return self._es.indices.get_index_template(name=template_name).body.get( | ||
"index_templates" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
from odd_collector_sdk.logger import logger | ||
|
||
logger = logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +0,0 @@ | ||
from .metadata import MetadataExtractor | ||
|
||
metadata_extractor = MetadataExtractor() | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from odd_models.models import DataEntity, DataEntityType, DataSet | ||
from oddrn_generator import ElasticSearchGenerator | ||
|
||
from odd_collector.adapters.elasticsearch.mappers.fields import map_field | ||
from odd_collector.adapters.elasticsearch.mappers.metadata import extract_index_metadata | ||
|
||
|
||
def map_index( | ||
index: dict, | ||
properties: dict, | ||
generator: ElasticSearchGenerator, | ||
) -> DataEntity: | ||
generator.set_oddrn_paths(indices=index["index"]) | ||
index_oddrn = generator.get_oddrn_by_path("indices") | ||
|
||
# field type with `@` prefix defines alias for another field in same index | ||
field_list = [ | ||
map_field(name, value, generator, "indices_fields") | ||
for name, value in properties.items() | ||
if not name.startswith("@") | ||
] | ||
|
||
return DataEntity( | ||
oddrn=index_oddrn, | ||
name=index["index"], | ||
owner=None, | ||
type=DataEntityType.TABLE, | ||
metadata=[extract_index_metadata(index)], | ||
dataset=DataSet(parent_oddrn=None, rows_number=0, field_list=field_list), | ||
) |
Oops, something went wrong.