Dec 2nd, 2026: [EN] Categorizing toys: ES|QL requests and dashboard building

The elves are curious.
Before the Christmas rush, they want to know how toy orders are distributed around the world.
So they set up an Elasticsearch cluster containing two indices: toys and children.
In these times of crisis, each child can only have one toy, but every child will get one.

Here are our two indices:

PUT children
{
  "mappings": {
    "properties": {
    "last_name":  { "type": "keyword" },
    "first_name": { "type": "keyword" },
    "birth_date": { "type": "date", "format": "yyyy-MM-dd" },
    "city":       { "type": "keyword" },
    "country":    { "type": "keyword" },
    "language":   { "type": "keyword" },
    "toy_id":     { "type": "keyword" }
    }
  }
}
PUT toys
{
  "settings": {
    "index.mode": "lookup"
  },
  "mappings": {
    "properties": {
    "toy_id":       { "type": "keyword" },
    "name":         { "type": "keyword" },
    "brand":        { "type": "keyword" },
    "price_usd":    { "type": "double" },
    "type":         { "type": "keyword" },
    "age_category": { "type": "keyword" }
    }
  }
}

Toys are sorted into categories (video games or physical games).
The first query shows how these categories are distributed among the children:

FROM children
| LOOKUP JOIN toys ON toy_id
| STATS nb_enfants = COUNT(*) BY type
| SORT nb_enfants DESC

A pie chart is a good fit, given the small number of categories.

The second query filters for video games and shows the top 10 orders:

FROM children
| LOOKUP JOIN toys ON toy_id
| WHERE type == "Video game"
| STATS nb_enfants = COUNT(*) BY name
| SORT nb_enfants DESC, name ASC
| LIMIT 10

A word cloud is then a good way to visualize this information.

The third query displays the distribution of languages spoken by children who ordered a physical game:

FROM children
| LOOKUP JOIN toys ON toy_id
| WHERE type == "Physical game"
| STATS nb_enfants = COUNT(*) BY language
| KEEP language, nb_enfants
| SORT nb_enfants DESC
| LIMIT 20

Finally, the last query calculates each child's age and, for those aged between 8 and 12, counts the number of physical games ordered:

FROM children
| EVAL age = DATE_DIFF("year", birth_date, NOW())
| WHERE age >= 8 AND age <= 12
| LOOKUP JOIN toys ON toy_id
| STATS
    physical_games = COUNT() WHERE type == "Physical game",
    video_games     = COUNT() WHERE type == "Video game"
  BY age
| KEEP age, physical_games
| SORT age

Each one of this visualisations can be added to a dashboard by clicking on the icon on the top right and then choose the dashboard.

Capture d’écran 2026-11-27 à 14.52.45

Wishing you a joyful holiday season!

5 Likes