🏡 Home 📖 Chapter Home 👉 Next
⚡ ElasticsearchBook.com is crafted by Jozef Sorocin and powered by:
As touched upon in the introduction to 3. Table & Charts, pagination requests are highly useful for building simple tables, lists, grids, and galleries.
In order to remain demand-oriented, you should aim to limit the response hits' content to only those attributes that are actually needed to populate said components. As such, you can specify, via the includes
parameter, which fields should be returned. Analogously, you can control which ones can be skipped via the excludes
parameter. Wildcards are supported too:
POST index_name/_search
{
"size": 24,
"from": 24,
"query": { ... },
"_source": {
"includes": ["id", "price", "photos"],
"excludes": ["irrelevant_field", "internal_*"]
}
}
The returned hits
would then function as the table rows, their attributes as the individual cells.
It's also possible to post-process an attribute's value so that it can be, say, rendered in the frontend without any further manipulation — think date formatting, applying a discount, or simply transforming a boolean into an emoji (as seen in Retool):
POST my_index/_search
{
...
"script_fields": {
"emoji_booleans": {
"script": {
"source": "doc['boolean_field'].value == true ? \\"✅\\" : \\"❌\\""
}
}
}
}
For further script_fields
applications see Script Fields & Debugging.
Let's imagine a typical e-commerce scenario — once the paginated & faceted e-shop is running, management is going to ask for:
Management would like to know
$0 < x ≤ $25
, $25 < x ≤ $100
and >$100
ranges