ElasticSearch中search after处理深分页介绍
2017-07-14 10:58
621 查看
原文地址:https://www.elastic.co/guide/en/elasticsearch/reference/5.5/search-request-search-after.html
Pagination of results can be done by using the
the cost becomes prohibitive when the deep pagination is reached. The
defaults to 10,000 is a safeguard, search requests take heap memory and time proportional to
is recommended for efficient deep scrolling but scroll contexts are costly and it is not recommended to use it for real time user requests. The
circumvents this problem by providing a live cursor. The idea is to use the results from the previous page to help the retrieval of the next page.
Suppose that the query to retrieve the first page looks like this:
COPY AS CURLVIEW
IN CONSOLE
A field with one unique value per document should be used as the tiebreaker of the sort specification. Otherwise the sort order for documents that have the same sort values would be undefined. The recommended way
is to use the field
is certain to contain one unique value for each document.
The result from the above request includes an array of
to start returning results "after" any document in the result list. For instance we can use the
retrieve the next page of results:
COPY AS CURLVIEW
IN CONSOLE
The parameter
be set to 0 (or -1) when
used.
not a solution to jump freely to a random page but rather to scroll many queries in parallel. It is very similar to the
but unlike it, the
is stateless, it is always resolved against the latest version of the searcher. For this reason the sort order may change during a walk depending on the updates and deletes of your index.
Search Afteredit
Pagination of results can be done by using the fromand
sizebut
the cost becomes prohibitive when the deep pagination is reached. The
index.max_result_windowwhich
defaults to 10,000 is a safeguard, search requests take heap memory and time proportional to
from + size. The Scroll api
is recommended for efficient deep scrolling but scroll contexts are costly and it is not recommended to use it for real time user requests. The
search_afterparameter
circumvents this problem by providing a live cursor. The idea is to use the results from the previous page to help the retrieval of the next page.
Suppose that the query to retrieve the first page looks like this:
GET twitter/tweet/_search { "size": 10, "query": { "match" : { "title" : "elasticsearch" } }, "sort": [ {"date": "asc"}, {"_uid": "desc"} ] }
COPY AS CURLVIEW
IN CONSOLE
A field with one unique value per document should be used as the tiebreaker of the sort specification. Otherwise the sort order for documents that have the same sort values would be undefined. The recommended way
is to use the field
_uidwhich
is certain to contain one unique value for each document.
The result from the above request includes an array of
sort valuesfor each document. These
sort valuescan be used in conjunction with the
search_afterparameter
to start returning results "after" any document in the result list. For instance we can use the
sort valuesof the last document and pass it to
search_afterto
retrieve the next page of results:
GET twitter/tweet/_search { "size": 10, "query": { "match" : { "title" : "elasticsearch" } }, "search_after": [1463538857, "tweet#654323"], "sort": [ {"date": "asc"}, {"_uid": "desc"} ] }
COPY AS CURLVIEW
IN CONSOLE
The parameter
frommust
be set to 0 (or -1) when
search_afteris
used.
search_afteris
not a solution to jump freely to a random page but rather to scroll many queries in parallel. It is very similar to the
scrollAPI
but unlike it, the
search_afterparameter
is stateless, it is always resolved against the latest version of the searcher. For this reason the sort order may change during a walk depending on the updates and deletes of your index.
相关文章推荐
- Elasticsearch中扫描和滚动处理深分页问题
- 形象介绍了.Net中的委托以及事件处理
- Jive中的分页处理
- 特殊分页处理
- 处理分页的数据函数GetlistByPage(strSQL, PageSize, PageNo, PageCount, arrList)
- 共享一个JS分页处理类(4)
- 共享一个JS分页处理的类(1)
- 使用工具类实现通用分页处理
- 用jscript处理repeater生成的表格, 实现分页打印
- PHP中模板分页的处理
- Jive笔记4--结果集分页处理
- 如何在Struts中进行分页处理
- java中的分页处理
- 使用SQL语句来进行分页处理
- 微软事务处理服务介绍
- Jive笔记4--结果集分页处理
- 分页的解析处理(ASP)
- 关于ROWID分页中,执行计划的错误选择与处理(二)
- ASP.NET分页的处理方式
- 共享一个JS分页处理的类(3)