问题描述:elasticsearch from和size分页查询得不到想要的结果
代码:
#分页
#from就相当于MySQL中limit后面的第一个参数
#from就相当于MySQL中limit后面的第二个参数
GET /my_index/_search
{
"query": {
"match_all": {}
},
"from": 1,
"size": 2
}
出错结果:
#①当 from为0时
{
"took" : 14,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "my_index",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"id" : 1,
"title" : "华为笔记本电脑",
"category" : "华为",
"images" : "http://www.gulixueyuan.com/xm.jpg",
"price" : 5388
}
},
{
"_index" : "my_index",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"id" : 2,
"title" : "华为手机",
"category" : "华为",
"images" : "http://www.gulixueyuan.com/xm.jpg",
"price" : 5500
}
}
]
}
}
②当from为1时
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "my_index",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"id" : 2,
"title" : "华为手机",
"category" : "华为",
"images" : "http://www.gulixueyuan.com/xm.jpg",
"price" : 5500
}
},
{
"_index" : "my_index",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"id" : 3,
"title" : "VIVO手机",
"category" : "vivo",
"images" : "http://www.gulixueyuan.com/xm.jpg",
"price" : 3600
}
}
]
}
}
问题描述: 当显示每页显示数量为2时,让from=0,再让from=1,数据出现了重叠