Elasticsearch 接受 from
和 size
参数:
size
显示应该返回的结果数量,默认是 10
from
显示应该跳过的初始结果数量,默认是 0
如果每页展示 5 条结果,可以用下面方式请求得到 1 到 3 页的结果:
GET /_search?size=5
GET /_search?size=5&from=5
GET /_search?size=5&from=10
响应体信息:
{
"took": 13,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 5,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "products",
"_type": "_doc",
"_id": "1567",
"_score": 1.0,
"_source": {
"product": "r2d2",
"details": "A resourceful astromech droid",
"tags": [
"droid"
]
}
},
{
"_index": "website",
"_type": "blog",
"_id": "1",
"_score": 1.0,
"_source": {
"title": "My first blog entry",
"text": "Just trying this out...",
"views": 1,
"tags": [
"testing"
]
}
},
{
"_index": "website",
"_type": "blog",
"_id": "123",
"_score": 1.0,
"_source": {
"title": "My first blog entry",
"text": "I am starting to get the hang of this...",
"date": "2014/01/02"
}
},
{
"_index": "website",
"_type": "blog",
"_id": "j_8Cb3oBGFbon3Ge-O8s",
"_score": 1.0,
"_source": {
"title": "My second blog entry",
"text": "Still trying this out...",
"date": "2021/07/04"
}
},
{
"_index": "website",
"_type": "blog",
"_id": "1if_seq_no=0&if_primary_term=1",
"_score": 1.0,
"_source": {
"title": "My first blog entry",
"text": "Starting to get the hang of this..."
}
}
]
}
}