private ResultStore buildStore(final SearchRequest searchRequest,
                                   final StatisticStoreDoc statisticStoreDoc) {
        Preconditions.checkNotNull(searchRequest);
        Preconditions.checkNotNull(statisticStoreDoc);

        final String searchKey = searchRequest.getKey().toString();

        // convert the search into something stats understands
        final SearchRequest modifiedSearchRequest = ExpressionUtil.replaceExpressionParameters(searchRequest);
        final FindEventCriteria criteria = StatStoreCriteriaBuilder.buildCriteria(
                statisticStoreDoc,
                modifiedSearchRequest.getQuery().getExpression(),
                modifiedSearchRequest.getDateTimeSettings());

        // Create coprocessors.
        final CoprocessorsImpl coprocessors =
                coprocessorsFactory.create(modifiedSearchRequest,
                        DataStoreSettings.createBasicSearchResultStoreSettings());
        final ResultStore resultStore = resultStoreFactory.create(
                searchRequest.getSearchRequestSource(),
                coprocessors);

        final Runnable runnable = taskContextFactory.context(TASK_NAME, taskContext -> {
            try {
                final AtomicBoolean destroyed = new AtomicBoolean();

                final SearchProcess searchProcess = new SearchProcess() {
                    @Override
                    public SearchTaskProgress getSearchTaskProgress() {
                        final TaskProgress taskProgress =
                                taskManager.getTaskProgress(taskContext);
                        if (taskProgress != null) {
                            return new SearchTaskProgress(
                                    taskProgress.getTaskName(),
                                    taskProgress.getTaskInfo(),
                                    taskProgress.getUserRef(),
                                    taskProgress.getThreadName(),
                                    taskProgress.getNodeName(),
                                    taskProgress.getSubmitTimeMs(),
                                    taskProgress.getTimeNowMs());
                        }
                        return null;
                    }

                    @Override
                    public void onTerminate() {
                        destroyed.set(true);
                        taskManager.terminate(taskContext.getTaskId());
                    }
                };

                // Set the search process.
                resultStore.setSearchProcess(searchProcess);

                // Don't begin execution if we have been asked to complete already.
                if (!destroyed.get()) {
                    // Create the object that will receive results.
                    LOGGER.debug(() -> "Starting search with key " + searchKey);
                    taskContext.info(() -> "Sql Statistics search " + searchKey + " - running query");

                    // Execute the search asynchronously.
                    // We have to create a wrapped runnable so that the task context references a managed task.
                    statisticsSearchService.search(
                            taskContext, statisticStoreDoc, criteria, coprocessors.getFieldIndex(), coprocessors,
                            coprocessors.getErrorConsumer());
                }

                coprocessors.getCompletionState().signalComplete();
                coprocessors.getCompletionState().awaitCompletion();
            } catch (final InterruptedException e) {
                LOGGER.trace(e::getMessage, e);
                // Keep interrupting this thread.
                Thread.currentThread().interrupt();
            }
        });
        executor.execute(runnable);

        LOGGER.debug(() -> "Async search task started for key " + searchKey);

        return resultStore;
    }
Turn the {@link StatisticStoreDoc} into an {@link List<QueryField>} object
<p>
This builds the standard set of fields for a statistics store, which can
be filtered by the relevant statistics store instance
stroom-statistics/stroom-statistics-impl-sql/src/main/java/stroom/statistics/impl/sql/search/SqlStatisticSearchProvider.java