AI Hints
Home›Elasticsearch Tutorial›More Queries, Sorting and Paging
Elasticsearch · Lesson 33 of 120

Paging and _source

From, size and fields.

⏱ 2 min read▶ Video at 30:15🎓 Free
Watch this lesson in the Elasticsearch courseWatch on YouTube ↗Full Elasticsearch course

A search might match hundreds of products, but a page shows ten. And each result card needs only a name and a price, not the whole document.

  • Hundreds of matches
  • Ten per page
  • Only what you show

Page two

Size is the page size. From is how many results to skip. So from three, size three, is page two. Run it. We get results four to six, sorted by price.

Dev Tools Consoletext
GET products/_search?filter_path=hits.hits._source
{
  "sort": [ { "price": "asc" } ],
  "_source": ["name", "price"],
  "from": 3,
  "size": 3
}
Output
{
  "hits": {
    "hits": [
      {
        "_source": {
          "name": "Solar Camp Lantern",
          "price": 33.99
        }
      },
      {
        "_source": {
          "name": "Rechargeable 600 Headlamp",
          "price": 35.99
        }
      },
      {
        "_source": {
          "name": "Dynamic 60m Climbing Rope",
          "price": 39.99
        }
      }
    ]
  }
}
Also uses _load
products

Paging rules

Page number n starts at from equals n minus one, times size. From plus size can't go past ten thousand by default. For deeper paging, use search after, which we'll see later. And_source picks the fields to return, so responses stay small.

keyvalue
Page nfrom = (n-1) × size
Limitfrom + size ≤ 10,000
Deep pagingsearch_after
_sourceonly needed fields

Summary

From and size page through results, and_source returns only the fields you need. Next, combining queries with bool.

Key takeaways
  • from
  • size
  • _source
Next up: The bool Query — combine everything