Esempio n. 1
0
        public Result <IndexRequest[], HttpStatusCode> GetAllElementsQueue()
        {
            var countResponse = _client.GetCount(_options.RequestsIndexName);

            if (!countResponse.IsValid)
            {
                return(ElasticSearchResponseConverter.ToResultOnFail <IndexRequest[]>(countResponse));
            }

            var responseFromElastic = _client.Search(search => search
                                                     .Index(_options.RequestsIndexName)
                                                     .Size((int)countResponse.Count)
                                                     .Sort(s => s.Descending(x => x.CreatedTime))
                                                     );

            if (!responseFromElastic.IsValid)
            {
                return(ElasticSearchResponseConverter.ToResultOnFail <IndexRequest[]>(responseFromElastic));
            }

            var results = responseFromElastic.Documents
                          .Select(x => x.ToModel())
                          .ToArray();

            return(Result <IndexRequest[], HttpStatusCode> .Success(results));
        }