-
Notifications
You must be signed in to change notification settings - Fork 274
DEV: add index lifecycle page #1064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
...t/develop/interact/search-and-query/best-practices/index-mgmt-best-practices.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| --- | ||
| Title: Index management best practices for Redis Query Engine | ||
| alwaysopen: false | ||
| categories: | ||
| - docs | ||
| - develop | ||
| - stack | ||
| - oss | ||
| - kubernetes | ||
| - clients | ||
| linkTitle: RQE index management | ||
| weight: 3 | ||
| --- | ||
|
|
||
| #### 1. Plan your indexes strategically | ||
| - Understand your query patterns: before creating indexes, analyze your expected query patterns to ensure indexes are optimized for performance. | ||
dwdougherty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - Avoid over-indexing: indexing every field increases memory usage and can slow down updates. Only index fields essential for your queries. | ||
| - Choose appropriate index types: use the correct field types (`TEXT`, `TAG`, `NUMERIC`, `GEO`, or `VECTOR`) for your data to maximize efficiency. | ||
dwdougherty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #### 2. Index creation | ||
| - Atomic creation: use the `FT.CREATE` command to atomically define an index schema. | ||
dwdougherty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - Field weighting: assign weights to `TEXT` fields to prioritize certain fields in full-text search results. | ||
| - Prefix optimization: leverage the `PREFIX` option to restrict indexing to keys with specific patterns. | ||
dwdougherty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - Data loading strategy: load data into Redis before creating an index when working with large datasets. Use the `ON HASH` or `ON JSON` options to match the data structure. | ||
|
|
||
| #### 3. Index aliasing | ||
| - What is index aliasing? | ||
dwdougherty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - Aliases act as abstracted names for indexes, allowing applications to reference the alias instead of the actual index name. This simplifies schema updates and index management. | ||
| - Use cases for index aliasing: | ||
| - Seamless schema updates: point the alias to a new index without changing application code. | ||
| - Version control: assign aliases like `products_live` to track the active index version. | ||
| - Testing and rollback: temporarily assign aliases to test indexes, and revert if needed. | ||
| - How to manage aliases: | ||
| - Assign an alias: `FT.ALIASADD my_alias my_index` | ||
| - Update an alias: `FT.ALIASUPDATE my_alias new_index` | ||
| - Remove an alias: `FT.ALIASDEL my_alias` | ||
|
|
||
| #### 4. Monitoring index population | ||
| - Check document count: | ||
| - Use the `FT.INFO` command to monitor the `num_docs` field, ensuring all expected documents are indexed. | ||
dwdougherty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
dwdougherty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - Example: | ||
| ```bash | ||
| FT.INFO my_new_index | ||
| ``` | ||
| - Run test queries: | ||
| - Validate data with sample queries to ensure proper indexing: | ||
| ```bash | ||
| FT.SEARCH my_new_index "*" | ||
| ``` | ||
| - Query profiling: | ||
dwdougherty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - Use `FT.PROFILE` to analyze query plans and validate performance: | ||
| ```bash | ||
| FT.PROFILE my_new_index SEARCH QUERY "your_query" | ||
| ``` | ||
| - Automate checks: | ||
| - Implement scripts to periodically verify document counts and query results. For example, in Python: | ||
| ```python | ||
| import redis | ||
|
|
||
| def check_index_readiness(index_name, expected_docs): | ||
| r = redis.StrictRedis(host='localhost', port=6379, decode_responses=True) | ||
| info = r.execute_command('FT.INFO', index_name) | ||
| num_docs = int(info[info.index('num_docs') + 1]) | ||
| return num_docs >= expected_docs | ||
|
|
||
| if check_index_readiness('my_new_index', 100000): | ||
| print("Index is fully populated!") | ||
| else: | ||
| print("Index is still populating...") | ||
| ``` | ||
|
|
||
| #### 5. Monitoring index performance | ||
dwdougherty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - Query profiling: use the `FT.PROFILE` command to analyze query performance and identify bottlenecks. | ||
| - Memory usage: regularly monitor memory usage with the `INFO memory` and `FT.INFO` commands to detect growth patterns and optimize resource allocation. | ||
| - Search query logs: enable query logging for better insights into how indexes are utilized. | ||
|
|
||
| #### 6. Index maintenance | ||
| - Reindexing: if schema changes are required, create a new index with the updated schema and reassign the alias once the index is ready. | ||
dwdougherty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - Expire old data: use Redis key expiration or TTLs to automatically remove outdated records and keep indexes lean. | ||
dwdougherty marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #### 7. Scaling and high availability | ||
| - Sharding considerations: in a clustered Redis setup, ensure indexes are designed with key distribution in mind to prevent query inefficiencies. | ||
| - Replication: test how indexes behave under replica promotion to ensure consistent query behavior across nodes. | ||
| - Active-Active support: if using Redis in an active-active setup, validate how index updates propagate to avoid inconsistencies. | ||
|
|
||
| #### 8. Versioning and testing | ||
| - Index versioning: when changing schemas, create a new version of the index alongside the old one and migrate data progressively. | ||
| - Staging environment: test index changes in a staging environment before deploying them to production. | ||
|
|
||
| #### 9. Cleaning up | ||
| - Index deletion: use the `FT.DROPINDEX` command to remove unused indexes and free up memory. Be cautious with the `DD` (Delete Documents) flag to avoid unintended data deletion. | ||
| - Monitoring orphaned keys: Ensure no keys remain that were previously associated with dropped indexes. | ||
|
|
||
| #### 10. Documentation and automation | ||
| - Maintain clear index schemas: document your index configurations to facilitate future maintenance. | ||
| - Automate index management: use scripts or orchestration tools to automate index creation, monitoring, and cleanup. | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.