简体   繁体   English

如何为弹性搜索添加分页

[英]How to add pagination for elastic search

I am using elastic search as searching tool in my application... 我在应用程序中使用弹性搜索作为搜索工具...

I am having 9 records in my db. 我的数据库中有9条记录。

My page size is 5. 我的页面大小是5。

So first time it will give me 5 records which is working fine by my code... 所以第一次它将给我5条记录,根据我的代码,它们可以正常工作...

Now second time when I scroll it should give me 4 records and then scrolling should give me 0 records. 现在第二次滚动时,它应该给我4条记录,然后滚动时应该给我0条记录。

{ {

   "from" : 0, "size" : size,
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}

I am using above code for query. 我正在使用上面的代码进行查询。

using above code the data is not coming proper as first time it is giving me 5 records, 2nd time also it is giving me 5 records then it will reduce count as 4,3,2. 使用上面的代码,数据不正确,因为第一次给我5条记录,第二次也给我5条记录,那么它将减少计数为4,3,2。

Kindly help me to allow pagination in my code. 请帮助我在代码中允许分页。

What do you specify the second time as from value? from价值中指定第二次? Can you post what you request in the second query call. 您可以在第二个查询调用中发布您的请求吗?

tip: It should be from: 5 and not from: 1 . 提示:应该from: 5而不是from: 1 It is not a page counter but a record counter. 它不是页面计数器,而是记录计数器。

You'll have to pass 你必须通过

1st time
"from" : 0,
"size" : 5


2nd time 
"from" : 5,
"size" : 5

Your query will be looking like 您的查询看起来像

{
  "query": {
    ... Your elasticsearch query
  },
  "_source": [
    .... Columns To retrieve
  ],
  "sort": [
    .... Sorting information
  ],
  "from": 0,
  "size": 5
}

This is for elasticsearch 2.3 这是针对elasticsearch 2.3

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

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