From 246cfff173f0e0f375e426bb4be95084c727657f Mon Sep 17 00:00:00 2001 From: Rachel Elledge Date: Mon, 26 Aug 2024 15:23:45 -0500 Subject: [PATCH 1/2] DOC-4178 Best practices for scalable Redis Query Engine --- .../search/scalable-query-best-practices.md | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 content/operate/oss_and_stack/stack-with-enterprise/search/scalable-query-best-practices.md diff --git a/content/operate/oss_and_stack/stack-with-enterprise/search/scalable-query-best-practices.md b/content/operate/oss_and_stack/stack-with-enterprise/search/scalable-query-best-practices.md new file mode 100644 index 0000000000..fd30f68432 --- /dev/null +++ b/content/operate/oss_and_stack/stack-with-enterprise/search/scalable-query-best-practices.md @@ -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]({{}}) 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]({{}}) + + - [Tag]({{}}) + + - [Vector]({{}}) + +- Result set types: + + - Small result sets + + - Document subsets that are indexed in their [non-normalized]({{}}) form + +## Indexing best practices + +Follow these best practices for [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]({{}}): + +- 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`]({{}}) 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 +``` From 241d5498c86d8d6de9b4d953d88b2599af641477 Mon Sep 17 00:00:00 2001 From: Rachel Elledge Date: Tue, 27 Aug 2024 15:06:52 -0500 Subject: [PATCH 2/2] Fix relref --- .../search/scalable-query-best-practices.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/operate/oss_and_stack/stack-with-enterprise/search/scalable-query-best-practices.md b/content/operate/oss_and_stack/stack-with-enterprise/search/scalable-query-best-practices.md index fd30f68432..be9fb986a2 100644 --- a/content/operate/oss_and_stack/stack-with-enterprise/search/scalable-query-best-practices.md +++ b/content/operate/oss_and_stack/stack-with-enterprise/search/scalable-query-best-practices.md @@ -10,7 +10,7 @@ linkTitle: Best practices for scalable Redis Query Engine weight: 25 --- -[Vertical scaling of Redis Query Engine]({{}}) 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. +[Vertical scaling of Redis Query Engine]({{}}) 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