[SYNPY-1893] Add search index tutorial - #1447
Draft
thomasyu888 wants to merge 1 commit into
Draft
Conversation
BryanFauble
reviewed
Aug 17, 2026
Comment on lines
+128
to
+149
| def wait_for_index(index: SearchIndex, timeout: int = 600) -> None: | ||
| """Wait until the search index has finished building. | ||
|
|
||
| Building the OpenSearch index behind a SearchIndex happens in the background | ||
| after `store()` returns. Until that build completes, a query against the | ||
| index either raises an error or reports zero hits. | ||
| """ | ||
| deadline = time.time() + timeout | ||
| while time.time() < deadline: | ||
| try: | ||
| results = index.query( | ||
| search_query=SearchQuery(query=Query(match_all={}), size=1), | ||
| response_parts=[SearchQueryPart.TOTAL_HITS], | ||
| ) | ||
| if results.total_hits: | ||
| print(f"Index {index.id} is queryable with {results.total_hits} rows") | ||
| return | ||
| except SynapseError: | ||
| pass # The index has not been created yet | ||
| print("Waiting for the search index to build...") | ||
| time.sleep(10) | ||
| raise TimeoutError(f"{index.id} did not finish building within {timeout} seconds") |
Member
There was a problem hiding this comment.
I don't think that this is needed. The asynch job and query pattern should be handling for this automatically. The only thing that might be a race condition is the query returning some, but not all results right away (Which this size=1 wouldn't catch)
On the Synapse backend side, even we don't know and we don't wait until all of the individual rows are queryable. The Synapse backend only budgets the time to ensure all of the data is accepted, and then turned on user side querying.
Member
Author
There was a problem hiding this comment.
Thanks! let me refine this tutorial first, as I haven't had a deep look at any of the claude generated content.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem:
No search index tutorial
Solution:
Added tutorial
Testing:
NA yet - will post link to the built documentation per branch