Lesson 3 — Structure and numbers #
Ranges, sorts, and cursor pagination over the sales collection (120
documents: type, price, qty, amount, merchant, status, date).
The types behind the data #
Numbers are indexed as their real types (float for price, integers for
qty), dates as epoch millis. That is what makes the queries below precise
— see the
field types reference for the
full catalog.
Ranges #
A
range query takes any combination of
gt/gte/lt/lte:
Dates work the same way — 92 sales in 2024, 28 in 2025:
Sorting #
The canonical sort clause names the field, direction, and where missing values land ( sort reference):
Add a second clause to break ties, and "_doc" or "_score" when you want
index order or relevance.
Cursor pagination #
from+size re-ranks everything before the offset — fine for page 3, wrong
for page 3000. Cursors (search_after) jump straight to the position after
a sort-key tuple. Take sort values from the last hit of the page above and
feed them back:
search_before pages backwards the same way. For a page-stable view across
requests, open a point-in-time snapshot first — see
API conventions.
Exact sets and existence #
terms matches a set of values;
exists checks presence:
50 — the 30 hats plus the 20 mugs you will meet again in the aggregation lesson.
What you learned #
- Ranges on numbers and dates, with explicit epoch millis.
- Canonical sort clauses and the cheap pseudo-fields.
search_after/search_beforecursors beat deepfrom.termsfor sets,existsfor presence.
Next: Lesson 4 — aggregations.