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


Java FiltersAggregationBuilder类代码示例

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


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

示例1: testEmpty

import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder; //导入依赖的package包/类
public void testEmpty() throws Exception {
    Directory directory = newDirectory();
    RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
    indexWriter.close();
    IndexReader indexReader = DirectoryReader.open(directory);
    IndexSearcher indexSearcher = newSearcher(indexReader, true, true);
    int numFilters = randomIntBetween(1, 10);
    QueryBuilder[] filters = new QueryBuilder[numFilters];
    for (int i = 0; i < filters.length; i++) {
        filters[i] = QueryBuilders.termQuery("field", randomAsciiOfLength(5));
    }
    FiltersAggregationBuilder builder = new FiltersAggregationBuilder("test", filters);
    builder.otherBucketKey("other");
    InternalFilters response = search(indexSearcher, new MatchAllDocsQuery(), builder, fieldType);
    assertEquals(response.getBuckets().size(), numFilters);
    for (InternalFilters.InternalBucket filter : response.getBuckets()) {
        assertEquals(filter.getDocCount(), 0);
    }
    indexReader.close();
    directory.close();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:FiltersAggregatorTests.java

示例2: testKeyedFilter

import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder; //导入依赖的package包/类
public void testKeyedFilter() throws Exception {
    Directory directory = newDirectory();
    RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
    Document document = new Document();
    document.add(new Field("field", "foo", fieldType));
    indexWriter.addDocument(document);
    document.clear();
    document.add(new Field("field", "else", fieldType));
    indexWriter.addDocument(document);
    // make sure we have more than one segment to test the merge
    indexWriter.commit();
    document.add(new Field("field", "foo", fieldType));
    indexWriter.addDocument(document);
    document.clear();
    document.add(new Field("field", "bar", fieldType));
    indexWriter.addDocument(document);
    document.clear();
    document.add(new Field("field", "foobar", fieldType));
    indexWriter.addDocument(document);
    indexWriter.commit();
    document.clear();
    document.add(new Field("field", "something", fieldType));
    indexWriter.addDocument(document);
    indexWriter.commit();
    document.clear();
    document.add(new Field("field", "foobar", fieldType));
    indexWriter.addDocument(document);
    indexWriter.close();

    IndexReader indexReader = DirectoryReader.open(directory);
    IndexSearcher indexSearcher = newSearcher(indexReader, true, true);

    FiltersAggregator.KeyedFilter[] keys = new FiltersAggregator.KeyedFilter[6];
    keys[0] = new FiltersAggregator.KeyedFilter("foobar", QueryBuilders.termQuery("field", "foobar"));
    keys[1] = new FiltersAggregator.KeyedFilter("bar", QueryBuilders.termQuery("field", "bar"));
    keys[2] = new FiltersAggregator.KeyedFilter("foo", QueryBuilders.termQuery("field", "foo"));
    keys[3] = new FiltersAggregator.KeyedFilter("foo2", QueryBuilders.termQuery("field", "foo"));
    keys[4] = new FiltersAggregator.KeyedFilter("same", QueryBuilders.termQuery("field", "foo"));
    // filter name already present so it should be merge with the previous one ?
    keys[5] = new FiltersAggregator.KeyedFilter("same", QueryBuilders.termQuery("field", "bar"));
    FiltersAggregationBuilder builder = new FiltersAggregationBuilder("test", keys);
    builder.otherBucket(true);
    builder.otherBucketKey("other");
    for (boolean doReduce : new boolean[] {true, false}) {
        final InternalFilters filters;
        if (doReduce) {
            filters = searchAndReduce(indexSearcher, new MatchAllDocsQuery(), builder, fieldType);
        } else {
            filters = search(indexSearcher, new MatchAllDocsQuery(), builder, fieldType);
        }
        assertEquals(filters.getBuckets().size(), 7);
        assertEquals(filters.getBucketByKey("foobar").getDocCount(), 2);
        assertEquals(filters.getBucketByKey("foo").getDocCount(), 2);
        assertEquals(filters.getBucketByKey("foo2").getDocCount(), 2);
        assertEquals(filters.getBucketByKey("bar").getDocCount(), 1);
        assertEquals(filters.getBucketByKey("same").getDocCount(), 1);
        assertEquals(filters.getBucketByKey("other").getDocCount(), 2);
    }

    indexReader.close();
    directory.close();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:63,代码来源:FiltersAggregatorTests.java

示例3: filters

import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder; //导入依赖的package包/类
/**
 * Create a new {@link Filters} aggregation with the given name.
 */
public static FiltersAggregationBuilder filters(String name) {
    return new FiltersAggregationBuilder(name);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:7,代码来源:AggregationBuilders.java

示例4: aggFilters

import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder; //导入依赖的package包/类
public SimpleAggregationBuilder<SimpleSearchQueryBuilder> aggFilters(String name) {
	FiltersAggregationBuilder filtersAgg = AggregationBuilders.filters(name);
	return agg(filtersAgg);
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:5,代码来源:SimpleSearchQueryBuilder.java

示例5: asFiltersAggregationBuilder

import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder; //导入依赖的package包/类
private FiltersAggregationBuilder asFiltersAggregationBuilder(){
	return (FiltersAggregationBuilder)this.aggsBuilder;
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:4,代码来源:SimpleSearchQueryBuilder.java


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