From 6362340be79b06927785f592b68585951439cbdd Mon Sep 17 00:00:00 2001 From: "David W. Dougherty" Date: Thu, 19 Sep 2024 12:44:23 -0700 Subject: [PATCH] DEV: add TCEs to query > aggregation page --- .../search-and-query/query/aggregation.md | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/content/develop/interact/search-and-query/query/aggregation.md b/content/develop/interact/search-and-query/query/aggregation.md index ca9fb23bf6..ad167b098d 100644 --- a/content/develop/interact/search-and-query/query/aggregation.md +++ b/content/develop/interact/search-and-query/query/aggregation.md @@ -46,9 +46,9 @@ Here is a more detailed explanation of the query syntax: The following example shows you how to calculate a discounted price for new bicycles: -``` +{{< clients-example query_agg agg1 >}} FT.AGGREGATE idx:bicycle "@condition:{new}" LOAD 2 "__key" "price" APPLY "@price - (@price * 0.1)" AS "discounted" -``` +{{< /clients-example >}} The field `__key` is a built-in field. @@ -92,9 +92,9 @@ Here is an explanation of the additional constructs: The following query shows you how to group by the field `condition` and apply a reduction based on the previously derived `price_category`. The expression `@price<1000` causes a bicycle to have the price category `1` if its price is lower than 1000 USD. Otherwise, it has the price category `0`. The output is the number of affordable bicycles grouped by price category. -``` +{{< clients-example query_agg agg2 >}} FT.AGGREGATE idx:bicycle "*" LOAD 1 price APPLY "@price<1000" AS price_category GROUPBY 1 @condition REDUCE SUM 1 "@price_category" AS "num_affordable" -``` +{{< /clients-example >}} ``` 1) "3" @@ -123,9 +123,9 @@ You can't use an aggregation function outside of a `GROUPBY` clause, but you can Here is an example that adds a type attribute `bicycle` to each document before counting all documents with that type: -``` +{{< clients-example query_agg agg3 >}} FT.AGGREGATE idx:bicycle "*" APPLY "'bicycle'" AS type GROUPBY 1 @type REDUCE COUNT 0 AS num_total -``` +{{< /clients-example >}} The result is: @@ -143,9 +143,9 @@ It's sometimes necessary to group your data without applying a mathematical aggr The following example shows how to group all bicycles by `condition`: -``` -FT.AGGREGATE idx:bicycle "*" LOAD 1 "__key" GROUPBY 1 "@condition" REDUCE TOLIST 1 "__key" AS bicylces -``` +{{< clients-example query_agg agg4 >}} +FT.AGGREGATE idx:bicycle "*" LOAD 1 "__key" GROUPBY 1 "@condition" REDUCE TOLIST 1 "__key" AS bicycles +{{< /clients-example >}} The output of this query is: @@ -153,18 +153,18 @@ The output of this query is: 1) "3" 2) 1) "condition" 1) "refurbished" - 2) "bicylces" + 2) "bicycles" 3) 1) "bicycle:9" 3) 1) "condition" 1) "used" - 2) "bicylces" + 2) "bicycles" 3) 1) "bicycle:1" 1) "bicycle:2" 2) "bicycle:3" 3) "bicycle:4" 4) 1) "condition" 1) "new" - 2) "bicylces" + 2) "bicycles" 3) 1) "bicycle:0" 1) "bicycle:5" 2) "bicycle:6"