1、如何使用es进行分页搜索的语法
size,from
GET test_index/test_type/_search?size=10&from=0
分页的上机实验
GET test_index/test_type/_search
运行结果
{
"took": 7,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 5,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "test_type",
"_id": "8",
"_score": 1,
"_source": {
"num": 1,
"tags": []
}
},
{
"_index": "test_index",
"_type": "test_type",
"_id": "2",
"_score": 1,
"_source": {
"test_field": "test2"
}
},
{
"_index": "test_index",
"_type": "test_type",
"_id": "6",
"_score": 1,
"_source": {
"test_field1": "test1",
"test_field2": "test123"
}
},
{
"_index": "test_index",
"_type": "test_type",
"_id": "1",
"_score": 1,
"_source": {
"test_field": "test123"
}
},
{
"_index": "test_index",
"_type": "test_type",
"_id": "3",
"_score": 1,
"_source": {
"test_field": "test3"
}
}
]
}
}
我们发现有5条数据,现在我们假设把这5条数据分成2页,每页3条数据,来实验分页搜索的效果。
第一页:
GET test_index/test_type/_search?from=0&size=3
运行结果
{
"took": 21,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 5,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "test_type",
"_id": "8",
"_score": 1,
"_source": {
"num": 1,
"tags": []
}
},
{
"_index": "test_index",
"_type": "test_type",
"_id": "2",
"_score": 1,
"_source": {
"test_field": "test2"
}
},
{
"_index": "test_index",
"_type": "test_type",
"_id": "6",
"_score": 1,
"_source": {
"test_field1": "test1",
"test_field2": "test123"
}
}
]
}
}
第二页
GET test_index/test_type/_search?from=3&size=3
运行结果
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 5,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "test_type",
"_id": "1",
"_score": 1,
"_source": {
"test_field": "test123"
}
},
{
"_index": "test_index",
"_type": "test_type",
"_id": "3",
"_score": 1,
"_source": {
"test_field": "test3"
}
}
]
}
}
第一页:id=8,2,6
第二页:id=1,3
2、什么是deep paging问题,为什么会产生这个问题,它的底层原理是什么?