public ExportMessagesCommand buildWithSearchOnly(Search search, ResultFormat resultFormat) {
        Query query = queryFrom(search);

        return builderFrom(resultFormat)
                .timeRange(resultFormat.timerange().orElse(toAbsolute(query.timerange())))
                .queryString(queryStringFrom(search, query))
                .usedSearchFilters(search.queries().stream()
                        .map(Query::filters)
                        .flatMap(List::stream)
                        .collect(Collectors.toList())
                )
                .streams(query.usedStreamIds())
                .build();
    }
@Test
    void appliesQueryDecorators() {
        Query q = validQueryBuilder().query(ElasticsearchQueryString.of("undecorated")).build();
        Search s = searchWithQueries(q);


        final QueryStringDecorators decorators = new QueryStringDecorators(Optional.of((queryString, parameterProvider, query) -> {
            if (queryString.equals("undecorated")) {
                return PositionTrackingQuery.of("decorated");
            } else {
                throw new IllegalArgumentException("Unexpected query " + queryString);
            }
        }));

        ExportMessagesCommand command = new CommandFactory(decorators).buildWithSearchOnly(s, ResultFormat.builder().build());

        assertThat(command.queryString()).isEqualTo(ElasticsearchQueryString.of("decorated"));
    }