public List<String> searchTags(@Nullable String textQuery, int page, int size) {
    int maxPageSize = 100;
    int maxPage = 20;
    checkArgument(size <= maxPageSize, "Page size must be lower than or equals to " + maxPageSize);
    checkArgument(page > 0 && page <= maxPage, "Page must be between 0 and " + maxPage);

    if (size <= 0) {
      return emptyList();
    }

    TermsAggregationBuilder tagFacet = AggregationBuilders.terms(FIELD_TAGS)
      .field(FIELD_TAGS)
      .size(size * page)
      .minDocCount(1)
      .order(BucketOrder.key(true));
    if (textQuery != null) {
      tagFacet.includeExclude(new IncludeExclude(".*" + escapeSpecialRegexChars(textQuery) + ".*", null));
    }

    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder()
      .query(authorizationTypeSupport.createQueryFilter())
      .fetchSource(false)
      .aggregation(tagFacet);

    SearchResponse response = client.search(EsClient.prepareSearch(TYPE_PROJECT_MEASURES.getMainType())
      .source(searchSourceBuilder));

    Terms aggregation = response.getAggregations().get(FIELD_TAGS);

    return aggregation.getBuckets().stream()
      .skip((page - 1) * size)
      .map(Bucket::getKeyAsString)
      .toList();
  }
@Test
  public void search_tags_follows_paging() {
    index(
      newDoc().setTags(newArrayList("finance", "offshore", "java")),
      newDoc().setTags(newArrayList("official", "javascript")),
      newDoc().setTags(newArrayList("marketing", "official")),
      newDoc().setTags(newArrayList("marketing", "Madhoff")),
      newDoc().setTags(newArrayList("finance", "offshore")),
      newDoc().setTags(newArrayList("offshore")));

    List<String> result = underTest.searchTags(null, 1, 3);
    assertThat(result).containsExactly("Madhoff", "finance", "java");

    result = underTest.searchTags(null, 2, 3);
    assertThat(result).containsExactly("javascript", "marketing", "official");

    result = underTest.searchTags(null, 3, 3);
    assertThat(result).containsExactly("offshore");

    result = underTest.searchTags(null, 3, 4);
    assertThat(result).isEmpty();
  }