public AllResponse <T> All(object query = null, IList <SortField> sort = null)
        {
            ElasticSearchPagedResponse <T> response = Paged(0, int.MaxValue, query, sort);

            return(new AllResponse <T>
            {
                Data = response.AllData(),
                TotalCount = response.TotalCount
            });
        }
        public ElasticSearchPagedResponse <T> Paged(int pageNumber, int pageSize, QueryContainer query, IList <SortField> sort)
        {
            // If the page number was invalid, use the default page number.
            pageNumber = Math.Max(DefaultPageNumber, pageNumber);

            // If the page size was invalid, use the default page size.
            pageSize = Math.Max(DefaultPageSize, pageSize);
            pageSize = Math.Min(pageSize, MaxPageSize);

            var content = new ElasticSearchPagedResponse <T>
            {
                Repository = this,
                Query      = query,
                Sort       = sort,
                PageNumber = pageNumber,
                PageSize   = pageSize
            };

            // Page numbers start at 0 for Elasticsearch.
            int from = (content.PageNumber - 1) * pageSize;
            ISearchResponse <T> searchResponse = Client.Search <T>(new SearchRequest <T>
            {
                Query = query,
                ///Sort = sort?.Cast<ISort>()?.ToList(),
                From = from,
                Size = pageSize
            });

            content.Data       = searchResponse.Documents.ToArray();
            content.TotalCount = searchResponse.Total;

            // If the page number is not in range, use the default search.
            if (content.StartItemIndex > content.TotalCount)
            {
                return(Paged(-1, -1, query, sort));
            }

            return(content);
        }