Exemple #1
0
        private void SkipNode (JSNode node, string name, Indices indices, int depth) {
            indices.GetNodeIndex();

            if (node is JSStatement)
                indices.GetStatementIndex();

            foreach (var e in VisitChildren(node, indices, depth)) {
                foreach (var c in e)
                    ;
            }
        }
Exemple #2
0
        private IEnumerable<State> VisitNode (JSNode node, string name = null, Indices indices = null, int depth = 0) {
            int? statementIndex = null;

            if (indices == null)
                indices = new Indices();

            int nodeIndex = indices.GetNodeIndex();

            if (node is JSStatement)
                statementIndex = indices.GetStatementIndex();

            yield return new State(
                node, name, depth, nodeIndex, statementIndex
            );

            foreach (var e in VisitChildren(node, indices, depth)) {
                foreach (var c in e)
                    yield return c;
            }
        }
		/// <inheritdoc/>
		public Task<IExistsResponse> TypeExistsAsync(Indices indices, Types types, Func<TypeExistsDescriptor, ITypeExistsRequest> selector = null) =>
			this.TypeExistsAsync(selector.InvokeOrDefault(new TypeExistsDescriptor(indices, types)));
		public IUpgradeResponse Upgrade(Indices indices, Func<UpgradeDescriptor, IUpgradeRequest> selector = null) =>
			this.Upgrade(selector.InvokeOrDefault(new UpgradeDescriptor().Index(indices)));
		/// <inheritdoc/>
		public ISegmentsResponse Segments(Indices indices, Func<SegmentsDescriptor, ISegmentsRequest> selector = null) =>
			this.Segments(selector.InvokeOrDefault(new SegmentsDescriptor().Index(indices)));
		/// <inheritdoc/>
		public IForceMergeResponse ForceMerge(Indices indices, Func<ForceMergeDescriptor, IForceMergeRequest> selector = null) =>
			this.ForceMerge(selector.InvokeOrDefault(new ForceMergeDescriptor().Index(indices)));
		/// <inheritdoc/>
		public Task<IClearCacheResponse> ClearCacheAsync(
			Indices indices,
			Func<ClearCacheDescriptor, IClearCacheRequest> selector = null,
			CancellationToken cancellationToken = default(CancellationToken)
		) => this.ClearCacheAsync(selector.InvokeOrDefault(new ClearCacheDescriptor().Index(indices)), cancellationToken);
Exemple #8
0
 /// <summary>
 /// <c>GET</c> request to the <c>ccr.follow_info</c> API, read more about this API online:
 /// <para></para>
 /// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html</a>
 /// </summary>
 public FollowInfoResponse FollowInfo(Indices index, Func <FollowInfoDescriptor, IFollowInfoRequest> selector = null) => FollowInfo(selector.InvokeOrDefault(new FollowInfoDescriptor(index: index)));
Exemple #9
0
        public void Test_Indices_Count()
        {
            var input = new Indices(0, 1);

            Assert.True(input.Count == 2);
        }
		/// <inheritdoc/>
		public Task<IIndicesOperationResponse> CloseIndexAsync(Indices indices, Func<CloseIndexDescriptor, ICloseIndexRequest> selector = null) =>
			this.CloseIndexAsync(selector.InvokeOrDefault(new CloseIndexDescriptor(indices)));
Exemple #11
0
 private bool IndexExists(string index)
 {
     return(_elasticClient.IndexExists(Indices.Index(index)).Exists);
 }
Exemple #12
0
 private void CleanIndex()
 {
     elasticClient.DeleteIndex(Indices.Index("sdresults"));
 }
Exemple #13
0
        private void CreateAliasForLastNIndices(int amount)
        {
            var           responseCatIndices  = _elasticClient.CatIndices(new CatIndicesRequest(Indices.Parse($"{_alias}-*")));
            var           records             = responseCatIndices.Records.ToList();
            List <string> indicesToAddToAlias = new List <string>();

            for (int i = amount; i > 0; i--)
            {
                if (_options.Value.IndexPerMonth)
                {
                    var indexName = $"{_alias}-{DateTime.UtcNow.AddMonths(-i + 1).ToString("yyyy-MM")}";
                    if (records.Exists(t => t.Index == indexName))
                    {
                        indicesToAddToAlias.Add(indexName);
                    }
                }
                else
                {
                    var indexName = $"{_alias}-{DateTime.UtcNow.AddDays(-i + 1).ToString("yyyy-MM-dd")}";
                    if (records.Exists(t => t.Index == indexName))
                    {
                        indicesToAddToAlias.Add(indexName);
                    }
                }
            }

            var response = _elasticClient.AliasExists(new AliasExistsRequest(new Names(new List <string> {
                _alias
            })));

            if (!response.IsValid)
            {
                throw response.OriginalException;
            }

            if (response.Exists)
            {
                _elasticClient.DeleteAlias(new DeleteAliasRequest(Indices.Parse($"{_alias}-*"), _alias));
            }

            Indices multipleIndicesFromStringArray = indicesToAddToAlias.ToArray();
            var     responseCreateIndex            = _elasticClient.PutAlias(new PutAliasRequest(multipleIndicesFromStringArray, _alias));

            if (!responseCreateIndex.IsValid)
            {
                throw responseCreateIndex.OriginalException;
            }
        }
 public CodeIndexerExpression(CodeExpression targetObject, params CodeExpression[] indices)
 {
     TargetObject = targetObject;
     Indices.AddRange(indices);
 }
Exemple #15
0
 public void AddIndex(int index)
 {
     Indices.Add(index);
 }
Exemple #16
0
    public static void Main(string[] args)
    {
        Storage db = StorageFactory.Instance.CreateStorage();

        db.Open("test1.dbs", pagePoolSize);
        Indices root = (Indices) db.GetRoot();
        if (root == null)
        {
            root = new Indices();
            root.strIndex = db.CreateIndex(typeof(string), true);
            root.intIndex = db.CreateFieldIndex(typeof(Record), "intKey", true);
            root.compoundIndex = db.CreateFieldIndex(typeof(Record), new string[]{"strKey", "intKey"}, true);
            db.SetRoot(root);
        }

        FieldIndex intIndex = root.intIndex;
        FieldIndex compoundIndex = root.compoundIndex;
        Index strIndex = root.strIndex;
        long start = (DateTime.Now.Ticks - 621355968000000000) / 10000;
        long key = 1999;
        int i;
        for (i = 0; i < nRecords; i++)
        {
            Record rec = new Record();
            key = (3141592621L * key + 2718281829L) % 1000000007L;
            rec.intKey = key;
            rec.strKey = Convert.ToString(key);
            rec.realKey = (double) key;
            intIndex.Put(rec);
            strIndex.Put(new Key(rec.strKey), rec);
            compoundIndex.Put(rec);
        }

        db.Commit();
        Console.Out.WriteLine("Elapsed time for inserting " + nRecords + " records: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds");

        start = (DateTime.Now.Ticks - 621355968000000000) / 10000;
        System.IO.StreamWriter writer = new System.IO.StreamWriter("test.xml", false, System.Text.Encoding.Default);
        db.ExportXML(writer);
        writer.Close();
        System.Console.Out.WriteLine("Elapsed time for XML export " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds");
        db.Close();
        db.Open("test2.dbs", pagePoolSize);

        start = (DateTime.Now.Ticks - 621355968000000000) / 10000;
        System.IO.StreamReader reader = new System.IO.StreamReader("test.xml", System.Text.Encoding.Default);
        db.ImportXML(reader);
        reader.Close();
        Console.Out.WriteLine("Elapsed time for XML import " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds");
        root = (Indices) db.GetRoot();
        intIndex = root.intIndex;
        strIndex = root.strIndex;
        compoundIndex = root.compoundIndex;

        start = (DateTime.Now.Ticks - 621355968000000000) / 10000;
        key = 1999;
        for (i = 0; i < nRecords; i++)
        {
            key = (3141592621L * key + 2718281829L) % 1000000007L;
            System.String strKey = Convert.ToString(key);
            Record rec1 = (Record) intIndex.Get(new Key(key));
            Record rec2 = (Record) strIndex.Get(new Key(strKey));
            Record rec3 = (Record) compoundIndex.Get(new Key(strKey, (long) key));
            Assert.That(rec1 != null);
            Assert.That(rec1 == rec2);
            Assert.That(rec1 == rec3);
            Assert.That(rec1.intKey == key);
            Assert.That(rec1.realKey == (double) key);
            Assert.That(strKey.Equals(rec1.strKey));
        }

        Console.Out.WriteLine("Elapsed time for performing " + nRecords * 2 + " index searches: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds");
        db.Close();
    }
Exemple #17
0
        public bool Test_Indices_Increment(int[] upperLimits)
        {
            var input = new Indices(upperLimits);

            return(input.Increment());
        }
		/// <inheritdoc/>
		public Task<IClearCacheResponse> ClearCacheAsync(Indices indices, Func<ClearCacheDescriptor, IClearCacheRequest> selector = null) => this.Dispatcher.DispatchAsync<IClearCacheRequest, ClearCacheRequestParameters, ClearCacheResponse, IClearCacheResponse>(
				selector.InvokeOrDefault(new ClearCacheDescriptor().Index(indices)),
				(p, d) => this.LowLevelDispatch.IndicesClearCacheDispatchAsync<ClearCacheResponse>(p)
			);
		/// <inheritdoc/>
		public IUpdateIndexSettingsResponse UpdateIndexSettings(Indices indices, Func<UpdateIndexSettingsDescriptor, IUpdateIndexSettingsRequest> selector) =>
			this.UpdateIndexSettings(selector.InvokeOrDefault(new UpdateIndexSettingsDescriptor().Index(indices)));
 public void Add(int index)
 {
     Indices.Add(index);
     Cost += Results[Indices.Count - 1].GetCost(index);
 }
		/// <inheritdoc/>
		public Task<IPutAliasResponse> PutAliasAsync(
			Indices indices,
			Name alias,
			Func<PutAliasDescriptor, IPutAliasRequest> selector = null,
			CancellationToken cancellationToken = default(CancellationToken)
		) => this.PutAliasAsync(selector.InvokeOrDefault(new PutAliasDescriptor(indices, alias)), cancellationToken);
		/// <inheritdoc/>
		public Task<IExistsResponse> IndexExistsAsync(Indices indices, Func<IndexExistsDescriptor, IIndexExistsRequest> selector = null) => 
			this.IndexExistsAsync(selector.InvokeOrDefault(new IndexExistsDescriptor(indices)));
Exemple #23
0
 /// <summary>
 /// <c>GET</c> request to the <c>ccr.follow_stats</c> API, read more about this API online:
 /// <para></para>
 /// <a href = "https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-stats.html">https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-stats.html</a>
 /// </summary>
 public Task <FollowIndexStatsResponse> FollowIndexStatsAsync(Indices index, Func <FollowIndexStatsDescriptor, IFollowIndexStatsRequest> selector = null, CancellationToken ct = default) => FollowIndexStatsAsync(selector.InvokeOrDefault(new FollowIndexStatsDescriptor(index: index)), ct);
		/// <inheritdoc/>
		public Task<IUpdateIndexSettingsResponse> UpdateIndexSettingsAsync(
			Indices indices,
			Func<UpdateIndexSettingsDescriptor, IUpdateIndexSettingsRequest> selector,
			CancellationToken cancellationToken = default(CancellationToken)
		) => this.UpdateIndexSettingsAsync(selector.InvokeOrDefault(new UpdateIndexSettingsDescriptor().Index(indices)), cancellationToken);
		/// <inheritdoc/>
		public Task<IShardsOperationResponse> RefreshAsync(Indices indices, Func<RefreshDescriptor, IRefreshRequest> selector = null) => 
			this.RefreshAsync(selector.InvokeOrDefault(new RefreshDescriptor().Index(indices)));
		/// <inheritdoc/>
		public Task<IDeleteWarmerResponse> DeleteWarmerAsync(Indices indices, Names names, Func<DeleteWarmerDescriptor, IDeleteWarmerRequest> selector = null) => 
			this.DeleteWarmerAsync(selector.InvokeOrDefault(new DeleteWarmerDescriptor(indices, names)));
		/// <inheritdoc/>
		public Task<IFlushResponse> FlushAsync(Indices indices, Func<FlushDescriptor, IFlushRequest> selector = null) => 
			this.FlushAsync(selector.InvokeOrDefault(new FlushDescriptor().Index(indices)));
		/// <inheritdoc/>
		public Task<ISegmentsResponse> SegmentsAsync(
			Indices indices,
			Func<SegmentsDescriptor, ISegmentsRequest> selector = null,
			CancellationToken cancellationToken = default(CancellationToken)
		) => this.SegmentsAsync(selector.InvokeOrDefault(new SegmentsDescriptor().Index(indices)), cancellationToken);
Exemple #29
0
        private IEnumerable<IEnumerable<State>> VisitChildren(JSNode node, Indices indices, int depth)
        {
            if (node == null)
                throw new ArgumentNullException("node");

            JSNode nextSibling = null;
            string nextSiblingName = null;

            int nextDepth = depth + 1;

            using (var e = node.Children.EnumeratorTemplate)
            while (e.MoveNext()) {
                var toVisit = nextSibling;
                var toVisitName = nextSiblingName;
                nextSibling = e.Current;
                nextSiblingName = e.CurrentName;

                if (toVisit != null) {
                    if (toVisitName == null || !NamesToSkip.Contains(toVisitName)) {
                        yield return VisitNode(toVisit, toVisitName, indices, nextDepth);
                    } else {
                        SkipNode(toVisit, toVisitName, indices, nextDepth);
                    }
                }
            }

            if (nextSibling != null) {
                if (nextSiblingName == null || !NamesToSkip.Contains(nextSiblingName)) {
                    yield return VisitNode(nextSibling, nextSiblingName, indices, nextDepth);
                } else {
                    SkipNode(nextSibling, nextSiblingName, indices, nextDepth);
                }
            }
        }
		/// <inheritdoc/>
		public Task<IForceMergeResponse> ForceMergeAsync(Indices indices, Func<ForceMergeDescriptor, IForceMergeRequest> selector = null, CancellationToken cancellationToken = default(CancellationToken)) =>
			this.ForceMergeAsync(selector.InvokeOrDefault(new ForceMergeDescriptor().Index(indices)), cancellationToken);
		/// <inheritdoc/>
		public ISyncedFlushResponse SyncedFlush(Indices indices, Func<SyncedFlushDescriptor, ISyncedFlushRequest> selector = null) =>
			this.SyncedFlush(selector.InvokeOrDefault(new SyncedFlushDescriptor().Index(indices)));
		/// <inheritdoc/>
		public Task<IRefreshResponse> RefreshAsync(Indices indices, Func<RefreshDescriptor, IRefreshRequest> selector = null, CancellationToken cancellationToken = default(CancellationToken)) =>
			this.RefreshAsync(selector.InvokeOrDefault(new RefreshDescriptor().Index(indices)), cancellationToken);
		/// <summary>
		/// Returns a collection of aliases that point to the specified index, simplified version of GetAlias.
		/// </summary>
		/// <param name="client">The client</param>
		/// <param name="indices">The index name(s) we want to know aliases of</param>
		public static IEnumerable<AliasDefinition> GetAliasesPointingToIndex(this IElasticClient client, Indices indices)
		{
			var aliasesResponse = client.GetAlias(a => a.Index(indices));
			return AliasesPointingToIndex(client.ConnectionSettings, indices, aliasesResponse);
		}
		public Task<IUpgradeResponse> UpgradeAsync(Indices indices, Func<UpgradeDescriptor, IUpgradeRequest> selector = null, CancellationToken cancellationToken = default(CancellationToken)) =>
			this.UpgradeAsync(selector.InvokeOrDefault(new UpgradeDescriptor().Index(indices)), cancellationToken);
		/// <summary>
		/// Returns a collection of aliases that point to the specified index, simplified version of GetAlias.
		/// </summary>
		/// <param name="client">The client</param>
		/// <param name="indices">The index name(s) we want to know aliases of</param>
		public static async Task<IEnumerable<AliasDefinition>> GetAliasesPointingToIndexAsync(this IElasticClient client, Indices indices)
		{
			var response = await client.GetAliasAsync(a => a.Index(indices)).ConfigureAwait(false);
			return AliasesPointingToIndex(client.ConnectionSettings, indices, response);
		}
		/// <inheritdoc/>
		public IRefreshResponse Refresh(Indices indices, Func<RefreshDescriptor, IRefreshRequest> selector = null) =>
			this.Refresh(selector.InvokeOrDefault(new RefreshDescriptor().Index(indices)));
		/// <inheritdoc/>
		public Task<IShardsOperationResponse> SyncedFlushAsync(Indices indices, Func<SyncedFlushDescriptor, ISyncedFlushRequest> selector = null) => 
			this.SyncedFlushAsync(selector.InvokeOrDefault(new SyncedFlushDescriptor().Index(indices)));
		/// <inheritdoc/>
		public Task<IRecoveryStatusResponse> RecoveryStatusAsync(Indices indices, Func<RecoveryStatusDescriptor, IRecoveryStatusRequest> selector = null) => 
			this.RecoveryStatusAsync(selector.InvokeOrDefault(new RecoveryStatusDescriptor().Index(indices)));
Exemple #39
0
    public static void Main(String[] args)
    {
        Storage db = StorageFactory.Instance.CreateStorage();
        bool serializableTransaction = false;
        for (int i = 0; i < args.Length; i++)
        {
            if ("inmemory".Equals(args[i]))
                pagePoolSize = StorageConstants.INFINITE_PAGE_POOL;
            else if ("altbtree".Equals(args[i]))
            {
                db.SetProperty("perst.alternative.btree", true);
                //db.SetProperty("perst.object.cache.kind", "weak");
                db.SetProperty("perst.object.cache.init.size", 1013);
            }
            else if ("serializable".Equals(args[i]))
            {
                db.SetProperty("perst.alternative.btree", true);
                serializableTransaction = true;
            }
            else
                Console.Error.WriteLine("Unrecognized option: " + args[i]);
        }
        db.Open("testidx.dbs", pagePoolSize);

        if (serializableTransaction)
            db.BeginThreadTransaction(StorageConstants.SERIALIZABLE_TRANSACTION);

        Indices root = (Indices) db.GetRoot();
        if (root == null)
        {
            root = new Indices();
            root.strIndex = db.CreateIndex(typeof(string), true);
            root.intIndex = db.CreateIndex(typeof(long), true);
            db.SetRoot(root);
        }

        Index intIndex = root.intIndex;
        Index strIndex = root.strIndex;
        long start = (DateTime.Now.Ticks - 621355968000000000) / 10000;
        long key = 1999;
        int i2;
        for (i2 = 0; i2 < nRecords; i2++)
        {
            Record rec = new Record();
            key = (3141592621L * key + 2718281829L) % 1000000007L;
            rec.intKey = key;
            rec.strKey = Convert.ToString(key);
            intIndex.Put(new Key(rec.intKey), rec);
            strIndex.Put(new Key(rec.strKey), rec);
            /*
            if (i % 100000 == 0) {
            System.out.print("Insert " + i + " records\r");
            db.Commit();
            }
            */
        }

        if (serializableTransaction)
        {
            db.EndThreadTransaction();
            db.BeginThreadTransaction(StorageConstants.SERIALIZABLE_TRANSACTION);
        }
        else
        {
            db.Commit();
        }
        //db.Gc();
        Console.Out.WriteLine("Elapsed time for inserting " + nRecords + " records: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds");

        start = (DateTime.Now.Ticks - 621355968000000000) / 10000;
        key = 1999;
        for (i2 = 0; i2 < nRecords; i2++)
        {
            key = (3141592621L * key + 2718281829L) % 1000000007L;
            Record rec1 = (Record) intIndex.Get(new Key(key));
            Record rec2 = (Record) strIndex.Get(new Key(Convert.ToString(key)));
            Assert.That(rec1 != null && rec1 == rec2);
        }
        Console.Out.WriteLine("Elapsed time for performing " + nRecords * 2 + " index searches: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds");

        start = (DateTime.Now.Ticks - 621355968000000000) / 10000;
        key = System.Int64.MinValue;
        i2 = 0;
        foreach (Record rec in intIndex)
        {
            Assert.That(rec.intKey >= key);
            key = rec.intKey;
            ++i2;
        }
        Assert.That(i2 == nRecords);
        string strKey = "";
        i2 = 0;
        foreach (Record rec in strIndex)
        {
            Assert.That(String.CompareOrdinal(rec.strKey, strKey) >= 0);
            strKey = rec.strKey;
            i2++;
        }
        Assert.That(i2 == nRecords);
        Console.Out.WriteLine("Elapsed time for iterating through " + (nRecords * 2) + " records: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds");

        //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior.
        Hashtable map = db.GetMemoryDump();
        Console.Out.WriteLine("Memory usage");
        start = (DateTime.Now.Ticks - 621355968000000000) / 10000;
        foreach (MemoryUsage usage in map.Values)
        {
            Console.Out.WriteLine(" " + usage.cls.FullName + ": instances=" + usage.nInstances + ", total size=" + usage.totalSize + ", allocated size=" + usage.allocatedSize);
        }
        Console.Out.WriteLine("Elapsed time for memory dump: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds");

        start = (DateTime.Now.Ticks - 621355968000000000) / 10000;
        key = 1999;
        for (i2 = 0; i2 < nRecords; i2++)
        {
            key = (3141592621L * key + 2718281829L) % 1000000007L;
            Record rec = (Record) intIndex.Get(new Key(key));
            Record removed = (Record) intIndex.Remove(new Key(key));
            Assert.That(removed == rec);
            //strIndex.Remove(new Key(Long.toString(key)), rec);
            strIndex.Remove(new Key(Convert.ToString(key)));
            rec.Deallocate();
        }

        Assert.That(!intIndex.GetEnumerator().MoveNext());
        Assert.That(!strIndex.GetEnumerator().MoveNext());
        Assert.That(!intIndex.GetEnumerator(null, null, IndexSortOrder.Descent).MoveNext());
        Assert.That(!strIndex.GetEnumerator(null, null, IndexSortOrder.Descent).MoveNext());
        Assert.That(!intIndex.GetEnumerator(null, null, IndexSortOrder.Ascent).MoveNext());
        Assert.That(!strIndex.GetEnumerator(null, null, IndexSortOrder.Ascent).MoveNext());
        Console.Out.WriteLine("Elapsed time for deleting " + nRecords + " records: " + ((DateTime.Now.Ticks - 621355968000000000) / 10000 - start) + " milliseconds");
        db.Close();
    }
		/// <inheritdoc/>
		public Task<IPutAliasResponse> PutAliasAsync(Indices indices, Name alias, Func<PutAliasDescriptor, IPutAliasRequest> selector = null) =>
			this.PutAliasAsync(selector.InvokeOrDefault(new PutAliasDescriptor(indices, alias)));
        /// <summary>
        /// Asynchronously gets the resources that match the given params
        /// </summary>
        /// <param name="query">Query parameters (optional)</param>
        /// <param name="size">Number of results to return (optional)</param>
        /// <param name="from">Beginning index for results (optional)</param>
        /// <param name="includeFields">Fields to include (optional)</param>
        /// <returns>Resource query result</returns>
        public async Task <ResourceQueryResult> QueryResourcesAsync(
            ResourceQuery query,
            int size = 20,
            int from = 0,
            string[] includeFields = null
            )
        {
            ResourceQueryResult queryResults = new ResourceQueryResult();

            // Set up the SearchRequest to send to the API.
            Indices       index   = Indices.Index(new string[] { this._apiOptions.AliasName });
            Types         types   = Types.Type(new string[] { "resource" });
            SearchRequest request = new SearchRequest(index, types)
            {
                Size = size,
                From = from,
                Sort = new List <ISort>
                {
                    new SortField {
                        Field = "title._sort", Order = SortOrder.Ascending
                    }
                },
                //TODO:
                Source = new SourceFilter
                {
                    Includes = includeFields
                }
            };

            //Add in the query
            var searchQuery = this.GetFullQuery(query.Keyword, query.Filters);

            if (searchQuery != null)
            {
                request.Query = searchQuery;
            }

            ISearchResponse <Resource> response = null;

            try
            {
                // Fetch the resources that match the given query and parameters from the API.
                response = await _elasticClient.SearchAsync <Resource>(request);
            }
            catch (Exception ex)
            {
                //TODO: Update error logger to include query
                _logger.LogError("Could not fetch resources for query.", ex);
                throw new APIErrorException(500, "Could not fetch resources for query.");
            }

            // If the API's response isn't valid, throw an error and return 500 status code.
            if (!response.IsValid)
            {
                _logger.LogError("Bad request.");
                throw new APIErrorException(500, "Errors occurred.");
            }

            // If the API finds resources matching the params, build the ResourceQueryResult to return.
            if (response.Total > 0)
            {
                // Build the array of resources for the returned restult.
                List <Resource> resourceResults = new List <Resource>();
                foreach (Resource res in response.Documents)
                {
                    resourceResults.Add(res);
                }

                queryResults.Results      = resourceResults.ToArray();
                queryResults.TotalResults = Convert.ToInt32(response.Total);
                queryResults.From         = from;
            }

            return(queryResults);
        }