private async Task Query(QueryOperationContext queryContext, OperationCancelToken token, RequestTimeTracker tracker, HttpMethod method, bool diagnostics) { var indexQuery = await GetIndexQuery(queryContext.Documents, method, tracker); indexQuery.Diagnostics = diagnostics ? new List <string>() : null; indexQuery.AddTimeSeriesNames = GetBoolValueQueryString("addTimeSeriesNames", false) ?? false; queryContext.WithQuery(indexQuery.Metadata); if (TrafficWatchManager.HasRegisteredClients) { TrafficWatchQuery(indexQuery); } var existingResultEtag = GetLongFromHeaders("If-None-Match"); if (indexQuery.Metadata.HasFacet) { await FacetedQuery(indexQuery, queryContext, token); return; } if (indexQuery.Metadata.HasSuggest) { await SuggestQuery(indexQuery, queryContext, token); return; } var metadataOnly = GetBoolValueQueryString("metadataOnly", required: false) ?? false; var shouldReturnServerSideQuery = GetBoolValueQueryString("includeServerSideQuery", required: false) ?? false; DocumentQueryResult result; try { result = await Database.QueryRunner.ExecuteQuery(indexQuery, queryContext, existingResultEtag, token).ConfigureAwait(false); } catch (IndexDoesNotExistException) { HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound; return; } if (result.NotModified) { HttpContext.Response.StatusCode = (int)HttpStatusCode.NotModified; return; } HttpContext.Response.Headers[Constants.Headers.Etag] = CharExtensions.ToInvariantString(result.ResultEtag); long numberOfResults; long totalDocumentsSizeInBytes; await using (var writer = new AsyncBlittableJsonTextWriter(queryContext.Documents, ResponseBodyStream())) { result.Timings = indexQuery.Timings?.ToTimings(); (numberOfResults, totalDocumentsSizeInBytes) = await writer.WriteDocumentQueryResultAsync(queryContext.Documents, result, metadataOnly, WriteAdditionalData(indexQuery, shouldReturnServerSideQuery), token.Token); } Database.QueryMetadataCache.MaybeAddToCache(indexQuery.Metadata, result.IndexName); AddPagingPerformanceHint(PagingOperationType.Queries, $"{nameof(Query)} ({result.IndexName})", indexQuery.Query, numberOfResults, indexQuery.PageSize, result.DurationInMs, totalDocumentsSizeInBytes); }