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


Java Cardinality类代码示例

本文整理汇总了Java中org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality的典型用法代码示例。如果您正苦于以下问题:Java Cardinality类的具体用法?Java Cardinality怎么用?Java Cardinality使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testSingleValuedStringValueScript

import org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality; //导入依赖的package包/类
public void testSingleValuedStringValueScript() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type")
            .addAggregation(
                    cardinality("cardinality")
                            .precisionThreshold(precisionThreshold)
                            .field("str_value")
                            .script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value", emptyMap())))
            .execute().actionGet();

    assertSearchResponse(response);

    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:CardinalityIT.java

示例2: testMultiValuedStringValueScript

import org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality; //导入依赖的package包/类
public void testMultiValuedStringValueScript() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type")
            .addAggregation(
                    cardinality("cardinality")
                            .precisionThreshold(precisionThreshold)
                            .field("str_values")
                            .script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value", emptyMap())))
            .execute().actionGet();

    assertSearchResponse(response);

    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs * 2);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:CardinalityIT.java

示例3: testSingleValuedNumericValueScript

import org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality; //导入依赖的package包/类
public void testSingleValuedNumericValueScript() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type")
            .addAggregation(
                    cardinality("cardinality")
                            .precisionThreshold(precisionThreshold)
                            .field(singleNumericField())
                            .script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value", emptyMap())))
            .execute().actionGet();

    assertSearchResponse(response);

    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:CardinalityIT.java

示例4: testMultiValuedNumericValueScript

import org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality; //导入依赖的package包/类
public void testMultiValuedNumericValueScript() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type")
            .addAggregation(
                    cardinality("cardinality")
                            .precisionThreshold(precisionThreshold)
                            .field(multiNumericField(false))
                            .script(new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_value", emptyMap())))
            .execute().actionGet();

    assertSearchResponse(response);

    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs * 2);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:CardinalityIT.java

示例5: executeCardinalityRequest

import org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality; //导入依赖的package包/类
protected void executeCardinalityRequest(final NodeTaskContext context, final NodeTaskReporter reporter) {
  logger.debug("Executing async cardinality action");
  final SearchRequest cardinalityRequest = this.getCardinalityRequest(context.getNode(), context.getVisitor().getParentRequest());
  context.getClient().execute(SearchAction.INSTANCE, cardinalityRequest, new ActionListener<SearchResponse>() {

    @Override
    public void onResponse(SearchResponse searchResponse) {
      Cardinality c = searchResponse.getAggregations().get(context.getNode().getLookupPath());
      context.getNode().setCardinality(c.getValue());
      reporter.success(context);
    }

    @Override
    public void onFailure(Throwable e) {
      reporter.failure(e);
    }

  });
}
 
开发者ID:sirensolutions,项目名称:siren-join,代码行数:20,代码来源:CardinalityEstimationTask.java

示例6: executeCardinary

import org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality; //导入依赖的package包/类
private long executeCardinary(String field) throws IOException{
	
	SearchResponse cardResponse = cardSearch.setAggregations(
			JsonXContent.contentBuilder()
			.startObject()
               	.startObject("LIMIT")
               		.startObject("cardinality")
               			.field("field", field)
               		.endObject()
               	.endObject()
			).get();

	Cardinality limit = cardResponse.getAggregations().get("LIMIT");
	
	return limit.getValue();		
}
 
开发者ID:huangchen007,项目名称:elasticsearch-rest-command,代码行数:17,代码来源:Search.java

示例7: getMap

import org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality; //导入依赖的package包/类
private Map<String, Object> getMap(List<String> fields, Aggregations aggregations) {
    final String field = fields.get(0);
    final List<String> remainingFields = (fields.size() > 1) ? fields.subList(1, fields.size())
            : new ArrayList<>();
    Terms terms = aggregations.get(Utils.sanitizeFieldForAggregation(field));
    Map<String, Object> levelCount = Maps.newHashMap();
    for (Terms.Bucket bucket : terms.getBuckets()) {
        if (fields.size() == 1) {
            if (!CollectionUtils.isNullOrEmpty(getParameter().getUniqueCountOn())) {
                String key = Utils.sanitizeFieldForAggregation(getParameter().getUniqueCountOn());
                Cardinality cardinality = bucket.getAggregations().get(key);
                levelCount.put(bucket.getKey(), cardinality.getValue());
            } else {
                levelCount.put(bucket.getKey(), bucket.getDocCount());
            }
        } else {
            levelCount.put(bucket.getKey(), getMap(remainingFields, bucket.getAggregations()));
        }
    }
    return levelCount;

}
 
开发者ID:Flipkart,项目名称:foxtrot,代码行数:23,代码来源:GroupAction.java

示例8: buildResponse

import org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality; //导入依赖的package包/类
private HistogramResponse buildResponse(Aggregations aggregations) {
    if (aggregations == null) {
        return new HistogramResponse(Collections.<HistogramResponse.Count>emptyList());
    }
    String dateHistogramKey = Utils.getDateHistogramKey(getParameter().getField());
    DateHistogram dateHistogram = aggregations.get(dateHistogramKey);
    Collection<? extends DateHistogram.Bucket> buckets = dateHistogram.getBuckets();
    List<HistogramResponse.Count> counts = new ArrayList<>(buckets.size());
    for (DateHistogram.Bucket bucket : buckets) {
        if (!CollectionUtils.isNullOrEmpty(getParameter().getUniqueCountOn())) {
            String key = Utils.sanitizeFieldForAggregation(getParameter().getUniqueCountOn());
            Cardinality cardinality = bucket.getAggregations().get(key);
            counts.add(new HistogramResponse.Count(bucket.getKeyAsNumber(), cardinality.getValue()));
        } else {
            counts.add(new HistogramResponse.Count(bucket.getKeyAsNumber(), bucket.getDocCount()));
        }
    }
    return new HistogramResponse(counts);
}
 
开发者ID:Flipkart,项目名称:foxtrot,代码行数:20,代码来源:HistogramAction.java

示例9: buildResponse

import org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality; //导入依赖的package包/类
private TrendResponse buildResponse(TrendRequest request, Aggregations aggregations) {
    String field = request.getField();
    Map<String, List<TrendResponse.Count>> trendCounts = new TreeMap<>();
    Terms terms = aggregations.get(Utils.sanitizeFieldForAggregation(field));
    for (Terms.Bucket bucket : terms.getBuckets()) {
        final String key = bucket.getKeyAsText().string();
        List<TrendResponse.Count> counts = Lists.newArrayList();
        Aggregations subAggregations = bucket.getAggregations();
        Histogram histogram = subAggregations.get(Utils.getDateHistogramKey(request.getTimestamp()));
        for (Histogram.Bucket histogramBucket : histogram.getBuckets()) {
            if (!CollectionUtils.isNullOrEmpty(getParameter().getUniqueCountOn())) {
                String uniqueCountKey = Utils.sanitizeFieldForAggregation(getParameter().getUniqueCountOn());
                Cardinality cardinality = histogramBucket.getAggregations().get(uniqueCountKey);
                counts.add(new TrendResponse.Count(histogramBucket.getKeyAsNumber(), cardinality.getValue()));
            } else {
                counts.add(new TrendResponse.Count(histogramBucket.getKeyAsNumber(), histogramBucket.getDocCount()));
            }
        }
        trendCounts.put(key, counts);
    }
    return new TrendResponse(trendCounts);
}
 
开发者ID:Flipkart,项目名称:foxtrot,代码行数:23,代码来源:TrendAction.java

示例10: assertCount

import org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality; //导入依赖的package包/类
private void assertCount(Cardinality count, long value) {
    if (value <= precisionThreshold) {
        // linear counting should be picked, and should be accurate
        assertEquals(value, count.getValue());
    } else {
        // error is not bound, so let's just make sure it is > 0
        assertThat(count.getValue(), greaterThan(0L));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:10,代码来源:CardinalityIT.java

示例11: testUnmapped

import org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality; //导入依赖的package包/类
public void testUnmapped() throws Exception {
    SearchResponse response = client().prepareSearch("idx_unmapped").setTypes("type")
            .addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field("str_value"))
            .execute().actionGet();

    assertSearchResponse(response);

    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, 0);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:CardinalityIT.java

示例12: testPartiallyUnmapped

import org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality; //导入依赖的package包/类
public void testPartiallyUnmapped() throws Exception {
    SearchResponse response = client().prepareSearch("idx", "idx_unmapped").setTypes("type")
            .addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field("str_value"))
            .execute().actionGet();

    assertSearchResponse(response);

    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:CardinalityIT.java

示例13: testSingleValuedString

import org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality; //导入依赖的package包/类
public void testSingleValuedString() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type")
            .addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field("str_value"))
            .execute().actionGet();

    assertSearchResponse(response);

    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:CardinalityIT.java

示例14: testSingleValuedNumeric

import org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality; //导入依赖的package包/类
public void testSingleValuedNumeric() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type")
            .addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field(singleNumericField()))
            .execute().actionGet();

    assertSearchResponse(response);

    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:CardinalityIT.java

示例15: testSingleValuedNumericHashed

import org.elasticsearch.search.aggregations.metrics.cardinality.Cardinality; //导入依赖的package包/类
public void testSingleValuedNumericHashed() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setTypes("type")
            .addAggregation(cardinality("cardinality").precisionThreshold(precisionThreshold).field(singleNumericField()))
            .execute().actionGet();

    assertSearchResponse(response);

    Cardinality count = response.getAggregations().get("cardinality");
    assertThat(count, notNullValue());
    assertThat(count.getName(), equalTo("cardinality"));
    assertCount(count, numDocs);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:13,代码来源:CardinalityIT.java


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