public Map<String, Long> countTags(IssueQuery query, int maxNumberOfTags) {
    Terms terms = listTermsMatching(FIELD_ISSUE_TAGS, query, null, BucketOrder.count(false), maxNumberOfTags);
    return EsUtils.termsToMap(terms);
  }
@Test
  void countTags() {
    ComponentDto project = newPrivateProjectDto();
    indexIssues(
      newDocForProject("issue1", project).setTags(Set.of("convention", "java8", "bug")),
      newDocForProject("issue2", project).setTags(Set.of("convention", "bug")),
      newDocForProject("issue3", project).setTags(emptyList()),
      newDocForProject("issue4", project).setTags(Set.of("convention", "java8", "bug")).setResolution(Issue.RESOLUTION_FIXED),
      newDocForProject("issue5", project).setTags(Set.of("convention")));

    assertThat(underTest.countTags(projectQuery(project.uuid()), 5)).containsOnly(entry("convention", 3L), entry("bug", 2L), entry("java8", 1L));
    assertThat(underTest.countTags(projectQuery(project.uuid()), 2)).contains(entry("convention", 3L), entry("bug", 2L)).doesNotContainEntry("java8", 1L);
    assertThat(underTest.countTags(projectQuery("other"), 10)).isEmpty();
  }