Skip to content

Commit 7102a3b

Browse files
committed
DEV: add index lifecycle page
1 parent 903735e commit 7102a3b

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
Title: Index management best practices for Redis Query Engine
3+
alwaysopen: false
4+
categories:
5+
- docs
6+
- develop
7+
- stack
8+
- oss
9+
- kubernetes
10+
- clients
11+
linkTitle: RQE index management
12+
weight: 3
13+
---
14+
15+
#### 1. Plan your indexes strategically
16+
- Understand your query patterns: before creating indexes, analyze your expected query patterns to ensure indexes are optimized for performance.
17+
- Avoid over-indexing: indexing every field increases memory usage and can slow down updates. Only index fields essential for your queries.
18+
- Choose appropriate index types: use the correct field types (`TEXT`, `TAG`, `NUMERIC`, `GEO`, or `VECTOR`) for your data to maximize efficiency.
19+
20+
#### 2. Index creation
21+
- Atomic creation: use the `FT.CREATE` command to atomically define an index schema.
22+
- Field weighting: assign weights to `TEXT` fields to prioritize certain fields in full-text search results.
23+
- Prefix optimization: leverage the `PREFIX` option to restrict indexing to keys with specific patterns.
24+
- 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.
25+
26+
#### 3. Index aliasing
27+
- What is index aliasing?
28+
- 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.
29+
- Use cases for index aliasing:
30+
- Seamless schema updates: point the alias to a new index without changing application code.
31+
- Version control: assign aliases like `products_live` to track the active index version.
32+
- Testing and rollback: temporarily assign aliases to test indexes, and revert if needed.
33+
- How to manage aliases:
34+
- Assign an alias: `FT.ALIASADD my_alias my_index`
35+
- Update an alias: `FT.ALIASUPDATE my_alias new_index`
36+
- Remove an alias: `FT.ALIASDEL my_alias`
37+
38+
#### 4. Monitoring index population
39+
- Check document count:
40+
- Use the `FT.INFO` command to monitor the `num_docs` field, ensuring all expected documents are indexed.
41+
- Example:
42+
```bash
43+
FT.INFO my_new_index
44+
```
45+
- Run test queries:
46+
- Validate data with sample queries to ensure proper indexing:
47+
```bash
48+
FT.SEARCH my_new_index "*"
49+
```
50+
- Query profiling:
51+
- Use `FT.PROFILE` to analyze query plans and validate performance:
52+
```bash
53+
FT.PROFILE my_new_index SEARCH QUERY "your_query"
54+
```
55+
- Automate checks:
56+
- Implement scripts to periodically verify document counts and query results. For example, in Python:
57+
```python
58+
import redis
59+
60+
def check_index_readiness(index_name, expected_docs):
61+
r = redis.StrictRedis(host='localhost', port=6379, decode_responses=True)
62+
info = r.execute_command('FT.INFO', index_name)
63+
num_docs = int(info[info.index('num_docs') + 1])
64+
return num_docs >= expected_docs
65+
66+
if check_index_readiness('my_new_index', 100000):
67+
print("Index is fully populated!")
68+
else:
69+
print("Index is still populating...")
70+
```
71+
72+
#### 5. Monitoring index performance
73+
- Query profiling: use the `FT.PROFILE` command to analyze query performance and identify bottlenecks.
74+
- Memory usage: regularly monitor memory usage with the `INFO memory` and `FT.INFO` commands to detect growth patterns and optimize resource allocation.
75+
- Search query logs: enable query logging for better insights into how indexes are utilized.
76+
77+
#### 6. Index maintenance
78+
- Reindexing: if schema changes are required, create a new index with the updated schema and reassign the alias once the index is ready.
79+
- Expire old data: use Redis key expiration or TTLs to automatically remove outdated records and keep indexes lean.
80+
81+
#### 7. Scaling and high availability
82+
- Sharding considerations: in a clustered Redis setup, ensure indexes are designed with key distribution in mind to prevent query inefficiencies.
83+
- Replication: test how indexes behave under replica promotion to ensure consistent query behavior across nodes.
84+
- Active-Active support: if using Redis in an active-active setup, validate how index updates propagate to avoid inconsistencies.
85+
86+
#### 8. Versioning and testing
87+
- Index versioning: when changing schemas, create a new version of the index alongside the old one and migrate data progressively.
88+
- Staging environment: test index changes in a staging environment before deploying them to production.
89+
90+
#### 9. Cleaning up
91+
- 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.
92+
- Monitoring orphaned keys: Ensure no keys remain that were previously associated with dropped indexes.
93+
94+
#### 10. Documentation and automation
95+
- Maintain clear index schemas: document your index configurations to facilitate future maintenance.
96+
- Automate index management: use scripts or orchestration tools to automate index creation, monitoring, and cleanup.

0 commit comments

Comments
 (0)