feat: expose refresh parameter in ElasticsearchDocumentStore and OpenSearchDocumentStore #2613
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related Issues
Closes #2065
Description
This PR exposes the
refreshparameter to relevant methods inElasticsearchDocumentStoreandOpenSearchDocumentStore, 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 underlyingrefreshparameter, giving users explicit control over this behavior.Changes
New
RefreshTypeparameter added to the following methods in both document stores:write_documents/write_documents_async"wait_for"delete_documents/delete_documents_async"wait_for"delete_all_documents/delete_all_documents_asyncTruedelete_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 operationFalse: 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=Trueinstead oftime.sleep(), making tests more reliable and faster.Additional Fixes
delete_all_documents_asyncin OpenSearch to setwait_for_completion=True(matching Elasticsearch behavior), ensuring the async delete operation completes before returning# ruff: noqa: FBT001, FBT002comment to OpenSearch to match Elasticsearch's linting configurationasyncioimport from Elasticsearch testsHow was this tested?
refreshparameterChecklist