Skip to content

Conversation

@GunaPalanivel
Copy link
Contributor

@GunaPalanivel GunaPalanivel commented Dec 16, 2025

Related Issues

Closes #2065

Description

This PR exposes the refresh parameter to relevant methods in ElasticsearchDocumentStore and OpenSearchDocumentStore, allowing users to control when index changes become visible to search operations.

Motivation

Both Elasticsearch and OpenSearch are "near real-time" search engines where changes are not immediately visible after write/update/delete operations. Previously, users had to use time.sleep() workarounds to ensure consistency. This change exposes the underlying refresh parameter, giving users explicit control over this behavior.

Changes

New RefreshType parameter added to the following methods in both document stores:

Method Default Value
write_documents / write_documents_async "wait_for"
delete_documents / delete_documents_async "wait_for"
delete_all_documents / delete_all_documents_async True
delete_by_filter / delete_by_filter_async "wait_for"
update_by_filter / update_by_filter_async "wait_for"

Parameter values:

  • True: Force refresh immediately after the operation
  • False: Do not refresh (better performance for bulk operations)
  • "wait_for": Wait for the next refresh cycle (default, ensures read-your-writes consistency)

Test Updates

Updated integration tests to use refresh=True instead of time.sleep(), making tests more reliable and faster.

Additional Fixes

  • Fixed delete_all_documents_async in OpenSearch to set wait_for_completion=True (matching Elasticsearch behavior), ensuring the async delete operation completes before returning
  • Added file-level # ruff: noqa: FBT001, FBT002 comment to OpenSearch to match Elasticsearch's linting configuration
  • Removed unused asyncio import from Elasticsearch tests

How was this tested?

  • Existing integration tests updated to use the new refresh parameter
  • All tests pass with the new implementation

Checklist

  • I have updated the related issue with new insights and changes
  • I added tests that prove my fix is effective or that my feature works
  • I added the docstrings to document new functions and parameters

@GunaPalanivel GunaPalanivel requested a review from a team as a code owner December 16, 2025 15:04
@GunaPalanivel GunaPalanivel requested review from anakin87 and removed request for a team December 16, 2025 15:04
@CLAassistant
Copy link

CLAassistant commented Dec 16, 2025

CLA assistant check
All committers have signed the CLA.

…SearchDocumentStore

Add configurable refresh parameter to write, delete, and update methods
in both ElasticsearchDocumentStore and OpenSearchDocumentStore.

This allows users to control when index changes become visible to search
operations, enabling read-your-writes consistency without relying on
time.sleep() workarounds.

Methods updated:
- write_documents / write_documents_async
- delete_documents / delete_documents_async
- delete_all_documents / delete_all_documents_async
- delete_by_filter / delete_by_filter_async
- update_by_filter / update_by_filter_async

The refresh parameter accepts:
- True: Force immediate refresh
- False: No refresh (best for bulk performance)
- "wait_for": Wait for next refresh cycle (default)

Closes deepset-ai#2065
@GunaPalanivel GunaPalanivel force-pushed the feature/elasticsearch-2605-expose-refresh-param branch from 94569c0 to 9a62b54 Compare December 16, 2025 15:15
@anakin87
Copy link
Member

@GunaPalanivel thanks for the contribution.

Please split your work into two distinct PRs, one targeting Elasticsearch and the other one about OpenSearch. This would help with the release process of this monorepo.

@GunaPalanivel
Copy link
Contributor Author

GunaPalanivel commented Dec 18, 2025

Thanks for the suggestion @anakin87!

Done - I've split this into two separate PRs:

@anakin87
Copy link
Member

Ok, thank you!

@anakin87 anakin87 closed this Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants