-
Notifications
You must be signed in to change notification settings - Fork 270
Best practices for scalable Redis Query Engine #606
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
Changes from all commits
Commits
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
99 changes: 99 additions & 0 deletions
99
...ate/oss_and_stack/stack-with-enterprise/search/scalable-query-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,99 @@ | ||
| --- | ||
| Title: Best practices for scalable Redis Query Engine | ||
| alwaysopen: false | ||
| categories: | ||
| - docs | ||
| - operate | ||
| - stack | ||
| description: Best practices for scalable Redis Query Engine in Redis Software and Redis Cloud. | ||
| linkTitle: Best practices for scalable Redis Query Engine | ||
| weight: 25 | ||
| --- | ||
|
|
||
| [Vertical scaling of Redis Query Engine]({{<relref "/operate/oss_and_stack/stack-with-enterprise/search/query-performance-factor">}}) requires configuring query performance factors. With careful crafting of search indices and queries, query performance factors allow throughput scaling up to 16X. The following recommendations help queries avoid accessing the keyspace and enable Redis Query Engine to benefit from additional CPUs allocated by query performance factors. | ||
|
|
||
| ## Best candidates for query performance factor improvements | ||
|
|
||
| - Query types: | ||
|
|
||
| - [Full-text]({{<relref "/develop/interact/search-and-query/query/full-text">}}) | ||
|
|
||
| - [Tag]({{<relref "/develop/interact/search-and-query/advanced-concepts/tags">}}) | ||
|
|
||
| - [Vector]({{<relref "/develop/interact/search-and-query/query/vector-search">}}) | ||
|
|
||
| - Result set types: | ||
|
|
||
| - Small result sets | ||
|
|
||
| - Document subsets that are indexed in their [non-normalized]({{<relref "/develop/interact/search-and-query/advanced-concepts/sorting#normalization-unf-option">}}) form | ||
|
|
||
| ## Indexing best practices | ||
|
|
||
| Follow these best practices for [indexing]({{<relref "/develop/interact/search-and-query/indexing">}}): | ||
|
|
||
| - Include fields in the index definition that are used in the query or the required result sets (projections). | ||
|
|
||
| - Use `SORTABLE` for all fields returned in result sets. | ||
|
|
||
| - Use the `UNF` option for `TAG` and `GEO` fields. | ||
|
|
||
| - Use the `NOSTEM` option for `TEXT` fields. | ||
|
|
||
| ## Query best practices | ||
|
|
||
| Follow these best practices for [queries]({{<relref "/develop/interact/search-and-query/query">}}): | ||
|
|
||
| - Specify the result set fields in the `RETURN` or `LOAD` clauses and include them in the index definition. Don’t just return the default result set from [`FT.SEARCH`]({{< baseurl >}}/commands/ft.search/) or `LOAD *` from [`FT.AGGREGATE`]({{< baseurl >}}/commands/ft.aggregate/). | ||
|
|
||
| - Use `LIMIT` to reduce the result set size. | ||
|
|
||
| - Use [`DIALECT 3`]({{<relref "/develop/interact/search-and-query/advanced-concepts/dialects#dialect-3">}}) or higher for any queries against JSON. | ||
|
|
||
| ## Index and query examples | ||
|
|
||
| The following examples depict an anti-pattern index schema and query, followed by a corrected schema and query, which allows for scalability with the Redis Query Engine. | ||
|
|
||
| ### Anti-pattern index schema | ||
|
|
||
| The following index schema is not optimized for vertical scaling: | ||
|
|
||
| ```sh | ||
| FT.CREATE jsonidx:profiles ON JSON PREFIX 1 profiles: | ||
| SCHEMA $.tags.* as t NUMERIC SORTABLE | ||
| $.firstName as name TEXT | ||
| $.location as loc GEO | ||
| ``` | ||
|
|
||
| ### Anti-pattern query | ||
|
|
||
| The following query is not optimized for vertical scaling: | ||
|
|
||
| ```sh | ||
| FT.AGGREGATE jsonidx:profiles '@t:[1299 1299]' LOAD * LIMIT 0 10 | ||
| ``` | ||
|
|
||
| ### Improved index schema | ||
|
|
||
| Here's an improved index schema that follows best practices for vertical scaling: | ||
|
|
||
| ```sh | ||
| FT.CREATE jsonidx:profiles ON JSON PREFIX 1 profiles: | ||
| SCHEMA $.tags.* as t NUMERIC SORTABLE | ||
| $.firstName as name TEXT NOSTEM SORTABLE | ||
| $.lastName as lastname TEXT NOSTEM SORTABLE | ||
| $.location as loc GEO SORTABLE | ||
| $.id as id TAG SORTABLE UNF | ||
| $.ver as ver TAG SORTABLE UNF | ||
| ``` | ||
|
|
||
| ### Improved query | ||
|
|
||
| Here's an improved query that follows best practices for vertical scaling: | ||
|
|
||
| ```sh | ||
| FT.AGGREGATE jsonidx:profiles '@t:[1299 1299]' | ||
| LOAD 6 id t nam" lastname loc ver | ||
| LIMIT 0 10 | ||
| DIALECT 3 | ||
| ``` | ||
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.