当前位置: 首页>>代码示例>>Java>>正文


Java SearchResult.getAggregations方法代码示例

本文整理汇总了Java中io.searchbox.core.SearchResult.getAggregations方法的典型用法代码示例。如果您正苦于以下问题:Java SearchResult.getAggregations方法的具体用法?Java SearchResult.getAggregations怎么用?Java SearchResult.getAggregations使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.searchbox.core.SearchResult的用法示例。


在下文中一共展示了SearchResult.getAggregations方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mapResults

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
public <T> AggregatedPage<T> mapResults(SearchResult response, Class<T> clazz, List<AbstractAggregationBuilder> aggregations, Pageable pageable) {

		LinkedList<T> results = new LinkedList<>();

		for (SearchResult.Hit<JsonObject, Void> hit : response.getHits(JsonObject.class)) {
			if (hit != null) {
				results.add(mapSource(hit.source, clazz));
			}
		}

		String scrollId = null;
		if (response instanceof ExtendedSearchResult) {
			scrollId = ((ExtendedSearchResult) response).getScrollId();
		}

		return new AggregatedPageImpl<>(results, pageable, response.getTotal(), response.getAggregations(), scrollId);
	}
 
开发者ID:VanRoy,项目名称:spring-data-jest,代码行数:18,代码来源:DefaultJestResultsMapper.java

示例2: getDateHistogram

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
public List<Pair<String, Long>> getDateHistogram(UsageLogSearchQuery searchQuery) {
    String query = getQuery(searchQuery);
    Search search = new Search.Builder(query)
            .addIndex(StatisticConstant.INDEX_NAME)
            .addType(StatisticConstant.INDEX_TYPE)
            .build();
    List<Pair<String, Long>> data = new ArrayList<>();
    try {
        SearchResult result = client.execute(search);
        MetricAggregation aggregation = result.getAggregations();
        DateHistogramAggregation dateHistogram = aggregation.getDateHistogramAggregation("event_over_time");
        for (DateHistogramAggregation.DateHistogram unit : dateHistogram.getBuckets()) {
            data.add(new Pair(unit.getTimeAsString(), unit.getCount()));
        }
    } catch (IOException ioe) {
        logger.log(Level.INFO, null, ioe);
    }
    return data;
}
 
开发者ID:pengchengluo,项目名称:Peking-University-Open-Research-Data-Platform,代码行数:20,代码来源:UsageLogSearchServiceBean.java

示例3: getResultTypeIndexSearchResponseDto

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
/**
 * Creates result type facet response dto
 *
 * @param searchResult search result
 *
 * @return result type facet response dto list
 */
public List<ResultTypeIndexSearchResponseDto> getResultTypeIndexSearchResponseDto(SearchResult searchResult)
{
    MetricAggregation metricAggregation = searchResult.getAggregations();
    TermsAggregation resultTypeAggregation = metricAggregation.getTermsAggregation(RESULT_TYPE_AGGS);

    List<TermsAggregation.Entry> buckets = resultTypeAggregation.getBuckets();

    List<ResultTypeIndexSearchResponseDto> resultTypeIndexSearchResponseDtos = new ArrayList<>();

    for (TermsAggregation.Entry entry : buckets)
    {
        ResultTypeIndexSearchResponseDto dto = new ResultTypeIndexSearchResponseDto();
        dto.setResultTypeCode(entry.getKeyAsString());
        dto.setResultTypeDisplayName(entry.getKeyAsString());
        dto.setCount(entry.getCount());
        resultTypeIndexSearchResponseDtos.add(dto);
    }

    return resultTypeIndexSearchResponseDtos;
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:28,代码来源:ElasticsearchHelper.java

示例4: getNestedTagTagIndexSearchResponseDto

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
/**
 * create tag tag index response dto
 *
 * @param searchResult search result
 *
 * @return tag type index search response dto list
 */
public List<TagTypeIndexSearchResponseDto> getNestedTagTagIndexSearchResponseDto(SearchResult searchResult)
{
    MetricAggregation metricAggregation = searchResult.getAggregations();
    MetricAggregation tagFacetAggregation = metricAggregation.getSumAggregation(TAG_FACET_AGGS);
    TermsAggregation tagTypeCodesAggregation = tagFacetAggregation.getTermsAggregation(TAGTYPE_CODE_AGGREGATION);
    return getTagTypeIndexSearchResponseDtosFromTermsAggregation(tagTypeCodesAggregation);
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:15,代码来源:ElasticsearchHelper.java

示例5: listOrgs

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
@SuppressWarnings("nls")
public void listOrgs(IAsyncResultHandler<List<String>> handler) {
    try {
        String query =
                "{\n" +
                "    \"aggs\" : {\n" +
                "        \"all_orgs\" : {\n" +
                "            \"terms\" : { \"field\" : \"organizationId\" }\n" + // i.e. only records containing an orgId field.
                "        }\n" +
                "    }\n" +
                "}";
        Search search = new Search.Builder(query)
                .addIndex(getIndexName())
                .setParameter(Parameters.SIZE, 0)
                .build();
        SearchResult response = getClient().execute(search);
        // Aggregations section
        MetricAggregation aggregation = response.getAggregations();
        // Look at the terms subsection
        TermsAggregation terms = aggregation.getTermsAggregation("all_orgs");
        // Grab only the name of each aggregation (we don't care about count
        List<String> results = terms.getBuckets().stream()
                .map(TermsAggregation.Entry::getKey)
                .collect(Collectors.toList());
        handler.handle(AsyncResultImpl.create(results));
    } catch (IOException e) {
        handler.handle(AsyncResultImpl.create(e));
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:31,代码来源:ESRegistry.java

示例6: getUsage

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
/**
 * @see io.apiman.manager.api.core.IMetricsAccessor#getUsage(java.lang.String, java.lang.String, java.lang.String, io.apiman.manager.api.beans.metrics.HistogramIntervalType, org.joda.time.DateTime, org.joda.time.DateTime)
 */
@SuppressWarnings("nls")
@Override
public UsageHistogramBean getUsage(String organizationId, String apiId, String version,
        HistogramIntervalType interval, DateTime from, DateTime to) {
    UsageHistogramBean rval = new UsageHistogramBean();
    Map<String, UsageDataPoint> index = generateHistogramSkeleton(rval, from, to, interval, UsageDataPoint.class);

    try {
        String query =
                "{" +
                "  \"query\": {" +
                "    \"filtered\" : {" +
                "      \"query\" : {" +
                "        \"range\" : {" +
                "          \"requestStart\" : {" +
                "            \"gte\": \"${from}\"," +
                "            \"lte\": \"${to}\"" +
                "          }" +
                "        }" +
                "      }," +
                "      \"filter\": {" +
                "        \"and\" : [" +
                "          { \"term\" : { \"apiOrgId\" : \"${apiOrgId}\" } }," +
                "          { \"term\" : { \"apiId\" : \"${apiId}\" } }," +
                "          { \"term\" : { \"apiVersion\" : \"${apiVersion}\" } }" +
                "        ]" +
                "      }" +
                "    }" +
                "  }," +
                "  \"size\": 0, " +
                "  \"aggs\" : {" +
                "      \"histogram\" : {" +
                "          \"date_histogram\" : {" +
                "              \"field\" : \"requestStart\"," +
                "              \"interval\" : \"${interval}\"" +
                "          }" +
                "      }" +
                "  }" +
                "}";
        Map<String, String> params = new HashMap<>();
        params.put("from", formatDate(from));
        params.put("to", formatDate(to));
        params.put("apiOrgId", organizationId.replace('"', '_'));
        params.put("apiId", apiId.replace('"', '_'));
        params.put("apiVersion", version.replace('"', '_'));
        params.put("interval", interval.name());
        StrSubstitutor ss = new StrSubstitutor(params);
        query = ss.replace(query);

        Search search = new Search.Builder(query).addIndex(INDEX_NAME).addType("request").build();
        SearchResult response = getEsClient().execute(search);
        MetricAggregation aggregations = response.getAggregations();
        DateHistogramAggregation aggregation = aggregations.getDateHistogramAggregation("histogram");
        if (aggregation != null) {
            List<DateHistogram> buckets = aggregation.getBuckets();
            for (DateHistogram entry : buckets) {
                String keyAsString = entry.getTimeAsString();
                if (index.containsKey(keyAsString)) {
                    index.get(keyAsString).setCount(entry.getCount());
                }
            }
        }
    } catch (IOException e) {
        log.error(e);
    }

    return rval;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:72,代码来源:ESMetricsAccessor.java

示例7: getUsagePerClient

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
/**
 * @see io.apiman.manager.api.core.IMetricsAccessor#getUsagePerClient(java.lang.String, java.lang.String, java.lang.String, org.joda.time.DateTime, org.joda.time.DateTime)
 */
@SuppressWarnings("nls")
@Override
public UsagePerClientBean getUsagePerClient(String organizationId, String apiId, String version,
        DateTime from, DateTime to) {
    UsagePerClientBean rval = new UsagePerClientBean();

    try {
        String query =
                "{" +
                "  \"query\": {" +
                "    \"filtered\" : {" +
                "      \"query\" : {" +
                "        \"range\" : {" +
                "          \"requestStart\" : {" +
                "            \"gte\": \"${from}\"," +
                "            \"lte\": \"${to}\"" +
                "          }" +
                "        }" +
                "      }," +
                "      \"filter\": {" +
                "        \"and\" : [" +
                "          { \"term\" : { \"apiOrgId\" : \"${apiOrgId}\" } }," +
                "          { \"term\" : { \"apiId\" : \"${apiId}\" } }," +
                "          { \"term\" : { \"apiVersion\" : \"${apiVersion}\" } }" +
                "        ]" +
                "      }" +
                "    }" +
                "  }," +
                "  \"size\": 0, " +
                "  \"aggs\" : {" +
                "      \"usage_by_client\" : {" +
                "        \"terms\" : {" +
                "          \"field\" : \"clientId\"" +
                "        }" +
                "      }" +
                "  }" +
                "}";
        Map<String, String> params = new HashMap<>();
        params.put("from", formatDate(from));
        params.put("to", formatDate(to));
        params.put("apiOrgId", organizationId.replace('"', '_'));
        params.put("apiId", apiId.replace('"', '_'));
        params.put("apiVersion", version.replace('"', '_'));
        StrSubstitutor ss = new StrSubstitutor(params);
        query = ss.replace(query);

        Search search = new Search.Builder(query).addIndex(INDEX_NAME).addType("request").build();
        SearchResult response = getEsClient().execute(search);
        MetricAggregation aggregations = response.getAggregations();
        ApimanTermsAggregation aggregation = aggregations.getAggregation("usage_by_client", ApimanTermsAggregation.class); //$NON-NLS-1$
        if (aggregation != null) {
            List<ApimanTermsAggregation.Entry> buckets = aggregation.getBuckets();
            int counter = 0;
            for (ApimanTermsAggregation.Entry entry : buckets) {
                rval.getData().put(entry.getKey(), entry.getCount());
                counter++;
                if (counter > 5) {
                    break;
                }
            }
        }
    } catch (IOException e) {
        log.error(e);
    }

    return rval;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:71,代码来源:ESMetricsAccessor.java

示例8: getUsagePerPlan

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
/**
 * @see io.apiman.manager.api.core.IMetricsAccessor#getUsagePerPlan(java.lang.String, java.lang.String, java.lang.String, org.joda.time.DateTime, org.joda.time.DateTime)
 */
@SuppressWarnings("nls")
@Override
public UsagePerPlanBean getUsagePerPlan(String organizationId, String apiId, String version,
        DateTime from, DateTime to) {
    UsagePerPlanBean rval = new UsagePerPlanBean();

    try {
        String query =
                "{" +
                "  \"query\": {" +
                "    \"filtered\" : {" +
                "      \"query\" : {" +
                "        \"range\" : {" +
                "          \"requestStart\" : {" +
                "            \"gte\": \"${from}\"," +
                "            \"lte\": \"${to}\"" +
                "          }" +
                "        }" +
                "      }," +
                "      \"filter\": {" +
                "        \"and\" : [" +
                "          { \"term\" : { \"apiOrgId\" : \"${apiOrgId}\" } }," +
                "          { \"term\" : { \"apiId\" : \"${apiId}\" } }," +
                "          { \"term\" : { \"apiVersion\" : \"${apiVersion}\" } }" +
                "        ]" +
                "      }" +
                "    }" +
                "  }," +
                "  \"size\": 0, " +
                "  \"aggs\" : {" +
                "      \"usage_by_plan\" : {" +
                "        \"terms\" : {" +
                "          \"field\" : \"planId\"" +
                "        }" +
                "      }" +
                "  }" +
                "}";
        Map<String, String> params = new HashMap<>();
        params.put("from", formatDate(from));
        params.put("to", formatDate(to));
        params.put("apiOrgId", organizationId.replace('"', '_'));
        params.put("apiId", apiId.replace('"', '_'));
        params.put("apiVersion", version.replace('"', '_'));
        StrSubstitutor ss = new StrSubstitutor(params);
        query = ss.replace(query);

        Search search = new Search.Builder(query).addIndex(INDEX_NAME).addType("request").build();
        SearchResult response = getEsClient().execute(search);
        MetricAggregation aggregations = response.getAggregations();
        ApimanTermsAggregation aggregation = aggregations.getAggregation("usage_by_plan", ApimanTermsAggregation.class); //$NON-NLS-1$
        if (aggregation != null) {
            List<ApimanTermsAggregation.Entry> buckets = aggregation.getBuckets();
            for (ApimanTermsAggregation.Entry entry : buckets) {
                rval.getData().put(entry.getKey(), entry.getCount());
            }
        }
    } catch (IOException e) {
        log.error(e);
    }

    return rval;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:66,代码来源:ESMetricsAccessor.java

示例9: getResponseStatsPerClient

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
/**
 * @see io.apiman.manager.api.core.IMetricsAccessor#getResponseStatsPerClient(java.lang.String, java.lang.String, java.lang.String, org.joda.time.DateTime, org.joda.time.DateTime)
 */
@Override
@SuppressWarnings("nls")
public ResponseStatsPerClientBean getResponseStatsPerClient(String organizationId, String apiId,
        String version, DateTime from, DateTime to) {
    ResponseStatsPerClientBean rval = new ResponseStatsPerClientBean();

    try {
        String query =
                "{" +
                "  \"query\": {" +
                "    \"filtered\" : {" +
                "      \"query\" : {" +
                "        \"range\" : {" +
                "          \"requestStart\" : {" +
                "            \"gte\": \"${from}\"," +
                "            \"lte\": \"${to}\"" +
                "          }" +
                "        }" +
                "      }," +
                "      \"filter\": {" +
                "        \"and\" : [" +
                "          { \"term\" : { \"apiOrgId\" : \"${apiOrgId}\" } }," +
                "          { \"term\" : { \"apiId\" : \"${apiId}\" } }," +
                "          { \"term\" : { \"apiVersion\" : \"${apiVersion}\" } }" +
                "        ]" +
                "      }" +
                "    }" +
                "  }," +
                "  \"size\": 0, " +
                "  \"aggs\" : {" +
                "      \"by_client\" : {" +
                "        \"terms\" : {" +
                "          \"field\" : \"clientId\"" +
                "        }," +
                "        \"aggs\" : {" +
                "          \"total_failures\" : {" +
                "            \"filter\" : { \"term\": { \"failure\": true } }" +
                "          }," +
                "          \"total_errors\" : {" +
                "            \"filter\" : { \"term\": { \"error\": true } }" +
                "          }" +
                "        }" +
                "      }" +
                "  }" +
                "}";
        Map<String, String> params = new HashMap<>();
        params.put("from", formatDate(from));
        params.put("to", formatDate(to));
        params.put("apiOrgId", organizationId.replace('"', '_'));
        params.put("apiId", apiId.replace('"', '_'));
        params.put("apiVersion", version.replace('"', '_'));
        StrSubstitutor ss = new StrSubstitutor(params);
        query = ss.replace(query);

        Search search = new Search.Builder(query).addIndex(INDEX_NAME).addType("request").build();
        SearchResult response = getEsClient().execute(search);
        MetricAggregation aggregations = response.getAggregations();
        ApimanTermsAggregation aggregation = aggregations.getAggregation("by_client", ApimanTermsAggregation.class); //$NON-NLS-1$
        if (aggregation != null) {
            List<ApimanTermsAggregation.Entry> buckets = aggregation.getBuckets();
            int counter = 0;
            for (ApimanTermsAggregation.Entry entry : buckets) {
                rval.addDataPoint(entry.getKey(), entry.getCount(), entry.getFilterAggregation("total_failures").getCount(),
                        entry.getFilterAggregation("total_errors").getCount());
                counter++;
                if (counter > 10) {
                    break;
                }
            }
        }
    } catch (IOException e) {
        log.error(e);
    }

    return rval;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:80,代码来源:ESMetricsAccessor.java

示例10: getResponseStatsPerPlan

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
/**
 * @see io.apiman.manager.api.core.IMetricsAccessor#getResponseStatsPerPlan(java.lang.String, java.lang.String, java.lang.String, org.joda.time.DateTime, org.joda.time.DateTime)
 */
@Override
@SuppressWarnings("nls")
public ResponseStatsPerPlanBean getResponseStatsPerPlan(String organizationId, String apiId,
        String version, DateTime from, DateTime to) {
    ResponseStatsPerPlanBean rval = new ResponseStatsPerPlanBean();

    try {
        String query =
                "{" +
                "  \"query\": {" +
                "    \"filtered\" : {" +
                "      \"query\" : {" +
                "        \"range\" : {" +
                "          \"requestStart\" : {" +
                "            \"gte\": \"${from}\"," +
                "            \"lte\": \"${to}\"" +
                "          }" +
                "        }" +
                "      }," +
                "      \"filter\": {" +
                "        \"and\" : [" +
                "          { \"term\" : { \"apiOrgId\" : \"${apiOrgId}\" } }," +
                "          { \"term\" : { \"apiId\" : \"${apiId}\" } }," +
                "          { \"term\" : { \"apiVersion\" : \"${apiVersion}\" } }" +
                "        ]" +
                "      }" +
                "    }" +
                "  }," +
                "  \"size\": 0, " +
                "  \"aggs\" : {" +
                "      \"by_plan\" : {" +
                "        \"terms\" : {" +
                "          \"field\" : \"planId\"" +
                "        }," +
                "        \"aggs\" : {" +
                "          \"total_failures\" : {" +
                "            \"filter\" : { \"term\": { \"failure\": true } }" +
                "          }," +
                "          \"total_errors\" : {" +
                "            \"filter\" : { \"term\": { \"error\": true } }" +
                "          }" +
                "        }" +
                "      }" +
                "  }" +
                "}";
        Map<String, String> params = new HashMap<>();
        params.put("from", formatDate(from));
        params.put("to", formatDate(to));
        params.put("apiOrgId", organizationId.replace('"', '_'));
        params.put("apiId", apiId.replace('"', '_'));
        params.put("apiVersion", version.replace('"', '_'));
        StrSubstitutor ss = new StrSubstitutor(params);
        query = ss.replace(query);

        Search search = new Search.Builder(query).addIndex(INDEX_NAME).addType("request").build();
        SearchResult response = getEsClient().execute(search);
        MetricAggregation aggregations = response.getAggregations();
        ApimanTermsAggregation aggregation = aggregations.getAggregation("by_plan", ApimanTermsAggregation.class); //$NON-NLS-1$
        if (aggregation != null) {
            List<ApimanTermsAggregation.Entry> buckets = aggregation.getBuckets();
            int counter = 0;
            for (ApimanTermsAggregation.Entry entry : buckets) {
                rval.addDataPoint(entry.getKey(), entry.getCount(), entry.getFilterAggregation("total_failures").getCount(),
                        entry.getFilterAggregation("total_errors").getCount());
                counter++;
                if (counter > 10) {
                    break;
                }
            }
        }
    } catch (IOException e) {
        log.error(e);
    }

    return rval;
}
 
开发者ID:apiman,项目名称:apiman,代码行数:80,代码来源:ESMetricsAccessor.java

示例11: getClientUsagePerApi

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
/**
 * @see io.apiman.manager.api.core.IMetricsAccessor#getClientUsagePerApi(java.lang.String, java.lang.String, java.lang.String, org.joda.time.DateTime, org.joda.time.DateTime)
 */
@Override
@SuppressWarnings("nls")
public ClientUsagePerApiBean getClientUsagePerApi(String organizationId, String clientId,
        String version, DateTime from, DateTime to) {
    ClientUsagePerApiBean rval = new ClientUsagePerApiBean();

    try {
        String query =
                "{" +
                "  \"query\": {\n" +
                "    \"filtered\" : {\n" +
                "      \"query\" : {\n" +
                "        \"range\" : {\n" +
                "          \"requestStart\" : {\n" +
                "            \"gte\": \"${from}\",\n" +
                "            \"lte\": \"${to}\"\n" +
                "          }\n" +
                "        }\n" +
                "      },\n" +
                "      \"filter\": {\n" +
                "        \"and\" : [\n" +
                "          { \"term\" : { \"clientOrgId\" : \"${clientOrgId}\" } },\n" +
                "          { \"term\" : { \"clientId\" : \"${clientId}\" } },\n" +
                "          { \"term\" : { \"clientVersion\" : \"${clientVersion}\" } }\n" +
                "        ]\n" +
                "      }\n" +
                "    }\n" +
                "  },\n" +
                "  \"size\": 0, \n" +
                "  \"aggs\" : {\n" +
                "      \"usage_by_api\" : {\n" +
                "        \"terms\" : {\n" +
                "          \"field\" : \"apiId\"\n" +
                "        }\n" +
                "      }\n" +
                "  }\n" +
                "}";
        Map<String, String> params = new HashMap<>();
        params.put("from", formatDate(from));
        params.put("to", formatDate(to));
        params.put("clientOrgId", organizationId.replace('"', '_'));
        params.put("clientId", clientId.replace('"', '_'));
        params.put("clientVersion", version.replace('"', '_'));
        StrSubstitutor ss = new StrSubstitutor(params);
        query = ss.replace(query);

        Search search = new Search.Builder(query).addIndex(INDEX_NAME).addType("request").build();
        SearchResult response = getEsClient().execute(search);
        MetricAggregation aggregations = response.getAggregations();
        ApimanTermsAggregation aggregation = aggregations.getAggregation("usage_by_api", ApimanTermsAggregation.class); //$NON-NLS-1$
        if (aggregation != null) {
            List<ApimanTermsAggregation.Entry> buckets = aggregation.getBuckets();
            for (ApimanTermsAggregation.Entry entry : buckets) {
                rval.getData().put(entry.getKey(), entry.getCount());
            }
        }
    } catch (IOException e) {
        log.error(e);
    }

    return rval;

}
 
开发者ID:apiman,项目名称:apiman,代码行数:67,代码来源:ESMetricsAccessor.java

示例12: listClients

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
@SuppressWarnings("nls")
public void listClients(String organizationId, int page, int pageSize, IAsyncResultHandler<List<String>> handler) {
    try {
        String query =
                "{\n" +
                "  \"query\": {\n" +
                "        \"filtered\": {\n" +
                "           \"query\": {\n" +
                "                \"match_all\": {}\n" +
                "           },\n" +
                "           \"filter\": {\n" +
                "               \"term\": {\n" +
                "                  \"organizationId\": ?\n" + // organizationId
                "               }\n" +
                "           }\n" +
                "        }\n" +
                "    },\n" +
                "    \"aggs\" : {\n" +
                "        \"clients\" : {\n" +
                "            \"terms\" : { \"field\" : \"clientId\" }\n" + // Only records with a clientId field
                "        }\n" +
                "    }\n" +
                "}";
        String escaped = ESUtils.queryWithEscapedArgs(query, organizationId);
        Search search = new Search.Builder(escaped)
                .addIndex(getIndexName())
                .setParameter(Parameters.SIZE, 0)
                .build();
        SearchResult response = getClient().execute(search);
        // Aggregations section
        MetricAggregation aggregation = response.getAggregations();
        // Look at the terms subsection
        TermsAggregation terms = aggregation.getTermsAggregation("clients");
        // Grab only the name of each aggregation (we don't care about count [for now]).
        List<String> results = terms.getBuckets().stream()
                .map(TermsAggregation.Entry::getKey)
                .collect(Collectors.toList());
        handler.handle(AsyncResultImpl.create(results));
    } catch (IOException e) {
        handler.handle(AsyncResultImpl.create(e));
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:44,代码来源:ESRegistry.java

示例13: listApis

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@SuppressWarnings("nls")
@Override
public void listApis(String organizationId, int page, int pageSize, IAsyncResultHandler<List<String>> handler) {
    try {
        String query =
                "{\n" +
                "  \"query\": {\n" +
                "        \"filtered\": {\n" +
                "           \"query\": {\n" +
                "                \"match_all\": {}\n" +
                "           },\n" +
                "           \"filter\": {\n" +
                "               \"term\": {\n" +
                "                  \"organizationId\": ?\n" + // organizationId
                "               }\n" +
                "           }\n" +
                "        }\n" +
                "    },\n" +
                "    \"aggs\" : {\n" +
                "        \"apis\" : {\n" +
                "            \"terms\" : { \"field\" : \"apiId\" }\n" + // Show only records containing an API ID field.
                "        }\n" +
                "    }\n" +
                "}";
        String escaped = ESUtils.queryWithEscapedArgs(query, organizationId);
        Search search = new Search.Builder(escaped)
                .addIndex(getIndexName())
                .setParameter(Parameters.SIZE, 0)
                .build();
        SearchResult response = getClient().execute(search);
        // Aggregations section
        MetricAggregation aggregation = response.getAggregations();
        // Look at the terms subsection
        TermsAggregation terms = aggregation.getTermsAggregation("apis");
        // Grab only the name of each aggregation (we don't care about count [for now]).
        List<String> results = terms.getBuckets().stream()
                .map(TermsAggregation.Entry::getKey)
                .collect(Collectors.toList());
        handler.handle(AsyncResultImpl.create(results));
    } catch (IOException e) {
        handler.handle(AsyncResultImpl.create(e));
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:44,代码来源:ESRegistry.java

示例14: listClientVersions

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
@SuppressWarnings("nls")
public void listClientVersions(String organizationId, String clientId, int page, int pageSize, IAsyncResultHandler<List<String>> handler) {
    try {
        String query =
                "{\n" +
                "  \"query\": {\n" +
                "    \"filtered\": {\n" +
                "      \"query\": {\n" +
                "        \"match_all\": {}\n" +
                "      },\n" +
                "      \"filter\": {\n" +
                "        \"bool\": {\n" +
                "          \"must\": [\n" +
                "            {\n" +
                "              \"term\": {\n" +
                "                \"organizationId\": ? \n" + // organizationId
                "              }\n" +
                "            },\n" +
                "            {\n" +
                "              \"term\": {\n" +
                "                \"clientId\": ? \n" + // clientId
                "              }\n" +
                "            }\n" +
                "          ]\n" +
                "        }\n" +
                "      }\n" +
                "    }\n" +
                "  },\n" +
                "  \"aggs\": {\n" +
                "    \"client_versions\": {\n" +
                "      \"terms\": {\n" +
                "        \"field\": \"version\"\n" +
                "      }\n" +
                "    }\n" +
                "  }\n" +
                "}";
        String escaped = ESUtils.queryWithEscapedArgs(query, organizationId, clientId);
        Search search = new Search.Builder(escaped)
                .addIndex(getIndexName())
                .setParameter(Parameters.SIZE, 0)
                .build();
        SearchResult response = getClient().execute(search);
        // Aggregations section
        MetricAggregation aggregation = response.getAggregations();
        // Look at the terms subsection
        TermsAggregation terms = aggregation.getTermsAggregation("client_versions");
        // Grab only the name of each aggregation
        List<String> results = terms.getBuckets().stream()
                .map(TermsAggregation.Entry::getKey)
                .collect(Collectors.toList());
        handler.handle(AsyncResultImpl.create(results));
    } catch (IOException e) {
        handler.handle(AsyncResultImpl.create(e));
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:57,代码来源:ESRegistry.java

示例15: listApiVersions

import io.searchbox.core.SearchResult; //导入方法依赖的package包/类
@Override
@SuppressWarnings("nls")
public void listApiVersions(String organizationId, String apiId, int page, int pageSize,
                            IAsyncResultHandler<List<String>> handler) {
    try {
        String query =
                "{\n" +
                "  \"query\": {\n" +
                "    \"filtered\": {\n" +
                "      \"query\": {\n" +
                "        \"match_all\": {}\n" +
                "      },\n" +
                "      \"filter\": {\n" +
                "        \"bool\": {\n" +
                "          \"must\": [\n" +
                "            {\n" +
                "              \"term\": {\n" +
                "                \"organizationId\": ? \n" + // organizationId
                "              }\n" +
                "            },\n" +
                "            {\n" +
                "              \"term\": {\n" +
                "                \"apiId\": ? \n" + // apiId
                "              }\n" +
                "            }\n" +
                "          ]\n" +
                "        }\n" +
                "      }\n" +
                "    }\n" +
                "  },\n" +
                "  \"aggs\": {\n" +
                "    \"api_versions\": {\n" +
                "      \"terms\": {\n" +
                "        \"field\": \"version\"\n" +
                "      }\n" +
                "    }\n" +
                "  }\n" +
                "}";
        String escaped = ESUtils.queryWithEscapedArgs(query, organizationId, apiId);
        Search search = new Search.Builder(escaped)
                .addIndex(getIndexName())
                .setParameter(Parameters.SIZE, 0)
                .build();
        SearchResult response = getClient().execute(search);
        // Aggregations section
        MetricAggregation aggregation = response.getAggregations();
        // Look at the terms subsection
        TermsAggregation terms = aggregation.getTermsAggregation("api_versions");
        // Grab only the name of each aggregation
        List<String> results = terms.getBuckets().stream()
                .map(TermsAggregation.Entry::getKey)
                .collect(Collectors.toList());
        handler.handle(AsyncResultImpl.create(results));
    } catch (IOException e) {
        handler.handle(AsyncResultImpl.create(e));
    }
}
 
开发者ID:apiman,项目名称:apiman,代码行数:58,代码来源:ESRegistry.java


注:本文中的io.searchbox.core.SearchResult.getAggregations方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。