--- Search From ---
POST users/_search
{
"from": 0,
"size": 10000,
"query": {
"match_all": {}
}
}
--- Search After ---
避免深度分页的性能问题,可以实时获取下一页文档信息
第一步搜索需要指定sort,并且保证值是唯一的(可以通过加入_id 保证唯一性)
然后使用上一次,最后一个文档sort值进行查询
DELETE users
POST users/_doc
{"name":"user1","age":10}
POST users/_doc
{"name":"user2","age":11}
POST users/_doc
{"name":"user3","age":12}
POST users/_doc
{"name":"user4","age":13}
POST users/_count
POST users/_search
{
"size": 1,
"query": {
"match_all": {}
},
"sort": [
{"age": {"order": "desc"}},
{"_id": {"order": "asc"}}
]
}
POST users/_search
{
"size": 2,
"query": {
"match_all": {}
},
"search_after":
[
13,
"2Mn8H20Bh4meypKEoD8Y"
]
,
"sort": [
{"age": {"order": "desc"}},
{"_id": {"order": "asc"}}
]
}
--- Scroll ---
创建一个快照,有新的数据写入以后,无法被查到
每次查询后,输入上一次的Scroll Id
POST /users/_search?scroll=5m
{
"size": 1 ,
"query": {
"match_all": {}
}
}
POST _search/scroll
{
"scroll":"1m",
"scroll_id":"DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAjEWeVpzQXR6ZF9TazJyWUNoVDR6bFVXdw=="
}
POST users/_search
{
"from": 0,
"size": 10000,
"query": {
"match_all": {}
}
}
--- 总结一下 ---