简体   繁体   English

使用Elasticsearch的虚拟滚动

[英]virtual scroll with elasticsearch

I'm using elasticsearch and kendo-ui grid. 我正在使用elasticsearch和kendo-ui网格。 Now I'm switching from endless scroll to virtual scroll. 现在,我从无穷滚动切换到虚拟滚动。 At the moment I use the Scroll Api in elasticsearch, but can't control the range for my request. 目前,我在elasticsearch中使用了Scroll Api,但无法控制我的请求的范围。

Is there a way to get a session like in scroll, where I could send the from and size ? 有没有一种方法可以像在滚动中那样获得会话,我可以在其中发送fromsize Or is there a better way to handle this? 还是有更好的方法来解决这个问题?

Use the search_after parameter in your search query. 在搜索查询中使用search_after参数。

search_after can be used when you sort your documents on one or multiple fields. 在一个或多个字段上对文档进行排序时,可以使用search_after In the search_after parameter you set the values for the fields that should be higher for all retrieved documents. search_after参数中,为所有检索到的文档设置应较高的字段值。

If you have for example a numeric field document_position with values from 0 to 1000. To retrieve the documents with document_position values higher than 200 you use the following query : 例如,如果您有一个数字字段document_position ,其值的范围是0到1000。要检索document_position值大于200的文档,请使用以下查询:

{
    "query": { // your query },
    "sort": "document_position",
    "search_after": [200]
}

You can use the score value in the search after parameter, but be aware that by default the score is not necessary consistent beetween search request . 您可以在参数之后的搜索中使用score值,但是请注意,默认情况下,得分在搜索请求之间不一定是一致的 The documentation presents a solution to this problem. 该文档提供了针对此问题的解决方案。 If you use the score (or any other field which is not unique for all documents), you will also have to sort on a second field that must be unique for all documents. 如果使用score (或并非所有文档都唯一的其他字段),则还必须对所有文档都必须唯一的第二个字段进行排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM