From ee51041ae76c6f709b427a66c57a2bf7defd46ab Mon Sep 17 00:00:00 2001
From: Liam Thompson <32779855+leemthompo@users.noreply.github.com>
Date: Wed, 11 Dec 2024 16:49:20 +0100
Subject: [PATCH] [DOCS][101] Aggregations quickstart tutorial (#116251)
(#118472)
(cherry picked from commit 56e1ca52ea38671a320c9e9421fe3cb8fe5f15e3)
# Conflicts:
# docs/reference/quickstart/index.asciidoc
---
.../quickstart/aggs-tutorial.asciidoc | 2184 +++++++++++++++++
docs/reference/quickstart/index.asciidoc | 2 +
2 files changed, 2186 insertions(+)
create mode 100644 docs/reference/quickstart/aggs-tutorial.asciidoc
diff --git a/docs/reference/quickstart/aggs-tutorial.asciidoc b/docs/reference/quickstart/aggs-tutorial.asciidoc
new file mode 100644
index 0000000000000..0a8494c3eb75d
--- /dev/null
+++ b/docs/reference/quickstart/aggs-tutorial.asciidoc
@@ -0,0 +1,2184 @@
+[[aggregations-tutorial]]
+== Analyze eCommerce data with aggregations using Query DSL
+++++
+Basics: Analyze eCommerce data with aggregations
+++++
+
+This hands-on tutorial shows you how to analyze eCommerce data using {es} <> with the `_search` API and Query DSL.
+
+You'll learn how to:
+
+* Calculate key business metrics such as average order value
+* Analyze sales patterns over time
+* Compare performance across product categories
+* Track moving averages and cumulative totals
+
+[discrete]
+[[aggregations-tutorial-requirements]]
+=== Requirements
+
+You'll need:
+
+. A running instance of <>, either on {serverless-full} or together with {kib} on Elastic Cloud Hosted/Self Managed deployments.
+** If you don't have a deployment, you can run the following command in your terminal to set up a <>:
++
+[source,sh]
+----
+curl -fsSL https://elastic.co/start-local | sh
+----
+// NOTCONSOLE
+. The {kibana-ref}/get-started.html#gs-get-data-into-kibana[sample eCommerce data] loaded into {es}. To load sample data follow these steps in your UI:
+* Open the *Integrations* pages by searching in the global search field.
+* Search for `sample data` in the **Integrations** search field.
+* Open the *Sample data* page.
+* Select the *Other sample data sets* collapsible.
+* Add the *Sample eCommerce orders* data set.
+This will create and populate an index called `kibana_sample_data_ecommerce`.
+
+[discrete]
+[[aggregations-tutorial-inspect-data]]
+=== Inspect index structure
+
+Before we start analyzing the data, let's examine the structure of the documents in our sample eCommerce index. Run this command to see the field <>:
+
+[source,console]
+----
+GET kibana_sample_data_ecommerce/_mapping
+----
+// TEST[skip:Using Kibana sample data]
+
+The response shows the field mappings for the `kibana_sample_data_ecommerce` index.
+
+.Example response
+[%collapsible]
+==============
+[source,console-response]
+----
+{
+ "kibana_sample_data_ecommerce": {
+ "mappings": {
+ "properties": {
+ "category": {
+ "type": "text",
+ "fields": { <1>
+ "keyword": {
+ "type": "keyword"
+ }
+ }
+ },
+ "currency": {
+ "type": "keyword"
+ },
+ "customer_birth_date": {
+ "type": "date"
+ },
+ "customer_first_name": {
+ "type": "text",
+ "fields": {
+ "keyword": {
+ "type": "keyword",
+ "ignore_above": 256
+ }
+ }
+ },
+ "customer_full_name": {
+ "type": "text",
+ "fields": {
+ "keyword": {
+ "type": "keyword",
+ "ignore_above": 256
+ }
+ }
+ },
+ "customer_gender": {
+ "type": "keyword"
+ },
+ "customer_id": {
+ "type": "keyword"
+ },
+ "customer_last_name": {
+ "type": "text",
+ "fields": {
+ "keyword": {
+ "type": "keyword",
+ "ignore_above": 256
+ }
+ }
+ },
+ "customer_phone": {
+ "type": "keyword"
+ },
+ "day_of_week": {
+ "type": "keyword"
+ },
+ "day_of_week_i": {
+ "type": "integer"
+ },
+ "email": {
+ "type": "keyword"
+ },
+ "event": {
+ "properties": {
+ "dataset": {
+ "type": "keyword"
+ }
+ }
+ },
+ "geoip": {
+ "properties": { <2>
+ "city_name": {
+ "type": "keyword"
+ },
+ "continent_name": {
+ "type": "keyword"
+ },
+ "country_iso_code": {
+ "type": "keyword"
+ },
+ "location": {
+ "type": "geo_point" <3>
+ },
+ "region_name": {
+ "type": "keyword"
+ }
+ }
+ },
+ "manufacturer": {
+ "type": "text",
+ "fields": {
+ "keyword": {
+ "type": "keyword"
+ }
+ }
+ },
+ "order_date": {
+ "type": "date"
+ },
+ "order_id": {
+ "type": "keyword"
+ },
+ "products": {
+ "properties": { <4>
+ "_id": {
+ "type": "text",
+ "fields": {
+ "keyword": {
+ "type": "keyword",
+ "ignore_above": 256
+ }
+ }
+ },
+ "base_price": {
+ "type": "half_float"
+ },
+ "base_unit_price": {
+ "type": "half_float"
+ },
+ "category": {
+ "type": "text",
+ "fields": {
+ "keyword": {
+ "type": "keyword"
+ }
+ }
+ },
+ "created_on": {
+ "type": "date"
+ },
+ "discount_amount": {
+ "type": "half_float"
+ },
+ "discount_percentage": {
+ "type": "half_float"
+ },
+ "manufacturer": {
+ "type": "text",
+ "fields": {
+ "keyword": {
+ "type": "keyword"
+ }
+ }
+ },
+ "min_price": {
+ "type": "half_float"
+ },
+ "price": {
+ "type": "half_float"
+ },
+ "product_id": {
+ "type": "long"
+ },
+ "product_name": {
+ "type": "text",
+ "fields": {
+ "keyword": {
+ "type": "keyword"
+ }
+ },
+ "analyzer": "english"
+ },
+ "quantity": {
+ "type": "integer"
+ },
+ "sku": {
+ "type": "keyword"
+ },
+ "tax_amount": {
+ "type": "half_float"
+ },
+ "taxful_price": {
+ "type": "half_float"
+ },
+ "taxless_price": {
+ "type": "half_float"
+ },
+ "unit_discount_amount": {
+ "type": "half_float"
+ }
+ }
+ },
+ "sku": {
+ "type": "keyword"
+ },
+ "taxful_total_price": {
+ "type": "half_float"
+ },
+ "taxless_total_price": {
+ "type": "half_float"
+ },
+ "total_quantity": {
+ "type": "integer"
+ },
+ "total_unique_products": {
+ "type": "integer"
+ },
+ "type": {
+ "type": "keyword"
+ },
+ "user": {
+ "type": "keyword"
+ }
+ }
+ }
+ }
+}
+----
+<1> `fields`: Multi-field mapping that allows both full text and exact matching
+<2> `geoip.properties`: Object type field containing location-related properties
+<3> `geoip.location`: Geographic coordinates stored as geo_point for location-based queries
+<4> `products.properties`: Nested structure containing details about items in each order
+==============
+
+The sample data includes the following <>:
+
+* <> and <> for text fields
+** Most `text` fields have a `.keyword` subfield for exact matching using <>
+* <> for date fields
+* 3 <> types:
+** `integer` for whole numbers
+** `long` for large whole numbers
+** `half_float` for floating-point numbers
+* <> for geographic coordinates
+* <