public ExportMessagesCommand buildWithMessageList(Search search, String messageListId, ResultFormat resultFormat) {
        Query query = search.queryForSearchType(messageListId);
        SearchType searchType = searchTypeFrom(query, messageListId);

        final List<Decorator> decorators = searchType instanceof MessageList ? ((MessageList) searchType).decorators() : Collections.emptyList();

        ExportMessagesCommand.Builder commandBuilder = builderFrom(resultFormat)
                .timeRange(resultFormat.timerange().orElse(toAbsolute(timeRangeFrom(query, searchType))))
                .queryString(queryStringFrom(search, query, searchType))
                .streams(query.effectiveStreams(searchType))
                .usedSearchFilters(query.filters())
                .attributeFilters(searchType instanceof HasAttributeFilter hasAttributeFilter ? hasAttributeFilter.attributes() : List.of())
                .decorators(decorators);

        return commandBuilder.build();
    }
@Test
    void throwsIfSearchTypeIsNotMessageList() {
        Pivot p = Pivot.builder().id("pivot-id").series(newArrayList()).rollup(false).build();

        Query q = org.graylog.plugins.views.search.TestData.validQueryBuilder().searchTypes(ImmutableSet.of(p)).build();

        Search s = searchWithQueries(q);

        assertThatExceptionOfType(ExportException.class)
                .isThrownBy(() -> sut.buildWithMessageList(s, p.id(), ResultFormat.builder().build()))
                .withMessageContaining("supported");
    }