Elastic Nest 7.x Query 获取 Total

track_total_hits

7.0 参考:https://www.elastic.co/guide/en/elasticsearch/reference/7.0/search-request-track-total-hits.html

7.8 参考: https://www.elastic.co/guide/en/elasticsearch/reference/7.8/search-request-body.html#request-body-search-track-total-hits

Query DSL

{
  "track_total_hits": true,
  "query": {
    "range": {
      "ts": {
        "gte": 0
      }
    }
  }
}

.net core Nest:

var search = _client.Search<SearchModel>(s => s
                    .From(pageFrom)
                    .Size(PageSize)
                    .TrackTotalHits(true)
                    .Query(q => MyQuery())
                    .Sort(t => MySort())
                );
                return search;



search.Total 就是真实的结果数

 

posted @ 2020-06-23 09:51  游子善心  阅读(20)  评论(0编辑  收藏  举报  来源