當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。