示例#1
0
        public async Task <APIResponse> GetAllRecords(string collectionName)
        {
            _logger.LogInformation($"GetAllRecords request recieved");

            var collection = await GetCollection(collectionName).ConfigureAwait(false);

            if (collection == null)
            {
                return(APIResponse.NotOk(Request.ToRequestString(), $"Cant find collection with name {collectionName}", HttpStatusCode.BadRequest));
            }

            var response = await _elasticBand.Query <object>(collection.Index, "").ConfigureAwait(false);

            if (response.Ok)
            {
                return new APIResponse
                       {
                           Request = Request.ToRequestString(),
                           Ok      = true,
                           Result  = "found",
                           Data    = response.Data
                       }
            }
            ;

            return(APIResponse.NotOk(Request.ToRequestString(), "No data or index doesn't exist", HttpStatusCode.NotFound));
        }
        private async Task <List <CollectionDefinition> > GetCollections()
        {
            var response = await _elasticBand.Query <CollectionDefinition>(CollectionsIndex.Name, "").ConfigureAwait(false);

            if (response.Ok)
            {
                return(response.Data);
            }

            return(null);
        }
示例#3
0
 /// <summary>
 /// Fetch objects (T) using a query.
 /// </summary>
 /// <param name="query">The query string, see documentation for examples</param>
 /// <param name="useQueryBuilder">A bool which determines if the query string should be used to generate ES query syntax to be used in the body of the request to Elasticsearch. Defaults to true.</param>
 /// <param name="limit">An int which if using the QueryBuilder, will liit the number of objects returned. Defaults to 500.</param>
 /// <returns>An ElasticBandResponse, where Data is a List<T> containing the matching objects.</returns>
 public async Task <ElasticBandResponse <List <T> > > Query(string query, bool useQueryBuilder = true, int limit = 500)
 {
     return(await _elasticBand.Query <T>(IndexName, query, useQueryBuilder, limit));
 }