Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1061 Cannot create custom index in python bingo-elastic #1165

Merged
merged 9 commits into from
Jul 13, 2023
25 changes: 17 additions & 8 deletions bingo/bingo-elastic/python/bingo_elastic/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,24 @@


class IndexName(Enum):
def __init__(self, value):
self._value_ = value

BINGO_MOLECULE = "bingo-molecules"
BINGO_REACTION = "bingo-reactions"
BINGO_CUSTOM = "custom-index"

def set_value(self, new_value):
self._value_ = new_value


def get_index_name(record: IndigoRecord) -> IndexName:
if isinstance(record, IndigoRecordMolecule):
return IndexName.BINGO_MOLECULE
if isinstance(record, IndigoRecordReaction):
return IndexName.BINGO_REACTION
if isinstance(record, str):
return IndexName.BINGO_CUSTOM
raise AttributeError(f"Unknown IndigoRecord type {record}")


Expand Down Expand Up @@ -143,14 +152,14 @@ async def a_create_index(


def prepare(
index_name: str, records: Generator[IndigoRecord, None, None]
records: Generator[IndigoRecord, None, None]
) -> Generator[Dict, None, None]:
for record in records:
if get_index_name(record).value != index_name:
raise ValueError(
f"Index {index_name} doesn't support store value "
f"of type {type(record)}"
)
# if get_index_name(record).value != index_name:
# raise ValueError(
# f"Index {index_name} doesn't support store value "
# f"of type {type(record)}"
# )
yield record.as_dict()


Expand Down Expand Up @@ -217,7 +226,7 @@ async def index_records(self, records: Generator, chunk_size: int = 500):
# pylint: disable=unused-variable
async for is_ok, action in async_streaming_bulk(
self.el_client,
prepare(self.index_name, records),
prepare(records),
index=self.index_name,
chunk_size=chunk_size,
):
Expand Down Expand Up @@ -307,7 +316,7 @@ def index_records(self, records: Generator, chunk_size: int = 500):
# pylint: disable=unused-variable
for is_ok, action in streaming_bulk(
self.el_client,
prepare(self.index_name, records),
prepare(records),
index=self.index_name,
chunk_size=chunk_size,
):
Expand Down
Loading