Skip to content

Commit

Permalink
increment doc_count on success only
Browse files Browse the repository at this point in the history
  • Loading branch information
toluaina committed Dec 26, 2023
1 parent d9c445a commit 6492fb2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pgsync/search_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def _bulk(
):
"""Bulk index, update, delete docs to Elasticsearch/OpenSearch."""
if settings.ELASTICSEARCH_STREAMING_BULK:
for _ in self.streaming_bulk(
for ok, _ in self.streaming_bulk(
self.__client,
actions,
index=index,
Expand All @@ -186,11 +186,12 @@ def _bulk(
raise_on_exception=raise_on_exception,
raise_on_error=raise_on_error,
):
self.doc_count += 1
if ok:
self.doc_count += 1
else:
# parallel bulk consumes more memory and is also more likely
# to result in 429 errors.
for _ in self.parallel_bulk(
for ok, _ in self.parallel_bulk(
self.__client,
actions,
thread_count=thread_count,
Expand All @@ -202,7 +203,8 @@ def _bulk(
raise_on_error=raise_on_error,
ignore_status=ignore_status,
):
self.doc_count += 1
if ok:
self.doc_count += 1

def refresh(self, indices: t.List[str]) -> None:
"""Refresh the Elasticsearch/OpenSearch index."""
Expand Down

0 comments on commit 6492fb2

Please sign in to comment.