ES查询支持分页

时间:2018-06-18 00:24:45

标签: elasticsearch

我在ES中有数据:

"hits": {
    "total": 177,
    "max_score": 1,
    "hits": [
            {
             "_id": "random_id_1",
             "_score": 1,
             "_source": {
                 "title": "Find series",
                 "description": "some random text",
                 "createdAt": 1527848716000,
                 "category": [
                     "STARS"
                 ],
                 "updatedAt": 1527848716000
               }
            },
            {
             "_id": "random_id_2",
             "_score": 1,
             "_source": {
                 "title": "Find series 2",
                 "description": "some random text 2",
                 "createdAt": 1527848716001,
                 "category": [
                     "SOLARS"
                 ],
                 "updatedAt": 1527848716001
               }
            }
         ]

需要的是显示每个类别的n个数据。使用聚合形成的查询:

    {
    "size": 0,
    "aggs": {
    "summary": {
      "terms": {
        "field": "category"
      },                                                              
      "aggs": {                                                          
        "summary": {                                             
          "top_hits": {                                                  
            "sort": [                                                    
              {                                                        
                "createdAt": "desc"                                     
              }                                                        
            ],
            "size": 100
          }                                                            
        }                                                              
      }
    }
  }
}

但我无法得到的是分页。如果我使用嵌套聚合,我可以有分页,但如果数据更新,从没有用。我想要的是基于_id的键集分页,但我无法弄清楚如何实现相同的目标?这里有任何帮助。感谢

0 个答案:

没有答案