public virtual IEnumerable <T> Search(BaseSearchModel request) { request.Size = request.Size == 0 ? 10000 : request.Size; var dynamicQuery = new List <QueryContainer>(); foreach (var item in request.Fields) { dynamicQuery.Add(Query <T> .Match(m => m.Field(new Field(item.Key.ToLower())).Query(item.Value))); } if (request._NumericRangeQuery != null) { var result = _elasticClient.Search <T>(s => s .Index(_indexName) .Size(request.Size) .Query(q => q.Range(o => request._NumericRangeQuery)) .Sort(ss => ss .Field(f => SortOrderCustom(f, request.orderProp, request.order)) ) ); if (!result.IsValid) { throw new Exception(result.OriginalException.Message); } return(result.Documents); } else { var dynamicarray = dynamicQuery.ToArray(); var result = _elasticClient.Search <T>(s => s .From(request.From) .Size(request.Size) .Index(_indexName) .Query(q => q.Bool(b => b.Must(dynamicarray))) .Sort(ss => ss .Field(f => SortOrderCustom(f, request.orderProp, request.order)) ) ); if (!result.IsValid) { throw new Exception(result.OriginalException.Message); } return(result.Documents); } }
public virtual IEnumerable <T> SearchAll(BaseSearchModel request) { return(_elasticClient.Search <T>(search => search .Sort(o => o.Field(c => SortOrderCustom(c, request.orderProp, request.order))) .MatchAll().Index(_indexName)).Documents); }