Skip to content

Commit

Permalink
#1061 Cannot create custom index in python bingo-elastic (#1165)
Browse files Browse the repository at this point in the history
  • Loading branch information
bodyangug authored Jul 13, 2023
1 parent c449ff9 commit dd67530
Showing 1 changed file with 17 additions and 8 deletions.
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

0 comments on commit dd67530

Please sign in to comment.