@Override
    @SuppressWarnings("nls")
    public void listOrgs(IAsyncResultHandler<List<String>> handler) {
        try {
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            // i.e. only records containing an organizationId field:
            TermsAggregationBuilder aggregation = AggregationBuilders.terms("all_orgs").field("organizationId");

            // keep searching in specific api mgmt indices to avoid search in foreign indices beside specific api-mgmt ones
            String[] indices = { getIndexPrefixWithJoiner() + EsConstants.INDEX_APIS, getIndexPrefixWithJoiner() + EsConstants.INDEX_CLIENTS};
            SearchRequest searchRequest = new SearchRequest(indices)
                    .source(searchSourceBuilder.aggregation(aggregation));
            SearchResponse searchResponse = getClient().search(searchRequest, RequestOptions.DEFAULT);

            List terms = ((ParsedTerms) searchResponse.getAggregations().asMap().get("all_orgs")).getBuckets();
            // Grab only the name of each aggregation (we don't care about count
            List<String> results = (List<String>) terms.stream()
                    .map(o -> ((ParsedTerms.ParsedBucket) o).getKey())
                    .collect(Collectors.toList());

            handler.handle(AsyncResultImpl.create(results));
        }
        catch (IOException e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
@see io.apiman.gateway.engine.IRegistry#getContract(java.lang.String, java.lang.String, java.lang.String, java.lang.String, io.apiman.gateway.engine.async.IAsyncResultHandler)
gateway/engine/es/src/main/java/io/apiman/gateway/engine/es/EsRegistry.java