ElasticsearchAutocompleteTags implements AutocompleteTags { @Override public Call<List<String>> getValues(String key) { if (key == null) throw new NullPointerException("key == null"); if (key.isEmpty()) throw new IllegalArgumentException("key was empty"); if (!enabled) return Call.emptyList(); long endMillis = System.currentTimeMillis(); long beginMillis = endMillis - namesLookback; List<String> indices = indexNameFormatter.formatTypeAndRange(TYPE_AUTOCOMPLETE, beginMillis, endMillis); if (indices.isEmpty()) return Call.emptyList(); SearchRequest.Filters filters = new SearchRequest.Filters().addTerm("tagKey", key); SearchRequest request = SearchRequest.create(indices) .filters(filters) .addAggregation(Aggregation.terms("tagValue", Integer.MAX_VALUE)); return search.newCall(request, BodyConverters.KEYS); } ElasticsearchAutocompleteTags(ElasticsearchStorage es); @Override Call<List<String>> getKeys(); @Override Call<List<String>> getValues(String key);  }
@Test void getValues_requestIncludesKeyName() throws Exception { server.enqueue(SUCCESS_RESPONSE); tagStore.getValues("http.method").execute(); assertThat(server.takeRequest().request().contentUtf8()).contains("\"tagKey\":\"http.method\""); }
@Test void getValues() throws Exception { server.enqueue(SUCCESS_RESPONSE); assertThat(tagStore.getValues("http.method").execute()).containsOnly("get", "post"); }