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


Java Terms.getBuckets方法代码示例

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


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

示例1: multipleGroupBysWithSize

import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入方法依赖的package包/类
@Test
public void multipleGroupBysWithSize() throws Exception {
    Set expectedAges = new HashSet<Integer>(ContiguousSet.create(Range.closed(20, 40), DiscreteDomain.integers()));

    Map<String, Set<Integer>> buckets = new HashMap<>();

    Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/account GROUP BY gender, terms('alias'='ageAgg','field'='age','size'=3)", TEST_INDEX));
    Terms gender = result.get("gender");
    Assert.assertEquals(2,gender.getBuckets().size());
    for(Terms.Bucket genderBucket : gender.getBuckets()) {

        String genderKey = genderBucket.getKey().toString();
        buckets.put(genderKey, new HashSet<Integer>());
        Terms ageBuckets = genderBucket.getAggregations().get("ageAgg");
        Assert.assertEquals(3,ageBuckets.getBuckets().size());

    }


}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:21,代码来源:AggregationTest.java

示例2: assertNoDocCountError

import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入方法依赖的package包/类
private void assertNoDocCountError(int size, SearchResponse accurateResponse, SearchResponse testResponse) {
    Terms accurateTerms = accurateResponse.getAggregations().get("terms");
    assertThat(accurateTerms, notNullValue());
    assertThat(accurateTerms.getName(), equalTo("terms"));
    assertThat(accurateTerms.getDocCountError(), equalTo(0L));

    Terms testTerms = testResponse.getAggregations().get("terms");
    assertThat(testTerms, notNullValue());
    assertThat(testTerms.getName(), equalTo("terms"));
    assertThat(testTerms.getDocCountError(), equalTo(0L));
    Collection<Bucket> testBuckets = testTerms.getBuckets();
    assertThat(testBuckets.size(), lessThanOrEqualTo(size));
    assertThat(accurateTerms.getBuckets().size(), greaterThanOrEqualTo(testBuckets.size()));

    for (Terms.Bucket testBucket : testBuckets) {
        assertThat(testBucket, notNullValue());
        Terms.Bucket accurateBucket = accurateTerms.getBucketByKey(testBucket.getKeyAsString());
        assertThat(accurateBucket, notNullValue());
        assertThat(accurateBucket.getDocCountError(), equalTo(0L));
        assertThat(testBucket.getDocCountError(), equalTo(0L));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:TermsDocCountErrorIT.java

示例3: reverseToRootGroupByOnNestedFieldWithFilterTestWithReverseNestedAndEmptyPath

import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入方法依赖的package包/类
@Test
public void reverseToRootGroupByOnNestedFieldWithFilterTestWithReverseNestedAndEmptyPath() throws Exception {
    Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/nestedType GROUP BY  nested(message.info),filter('myFilter',message.info = 'a'),reverse_nested(someField,'')", TEST_INDEX));
    InternalNested nested = result.get("[email protected]");
    InternalFilter filter = nested.getAggregations().get("[email protected]");
    Terms infos = filter.getAggregations().get("message.info");
    Assert.assertEquals(1,infos.getBuckets().size());
    for(Terms.Bucket bucket : infos.getBuckets()) {
        InternalReverseNested reverseNested = bucket.getAggregations().get("[email protected]");
        Terms terms = reverseNested.getAggregations().get("someField");
        Terms.Bucket internalBucket = terms.getBuckets().get(0);

        long count = ((ValueCount) internalBucket.getAggregations().get("COUNT(*)")).getValue();
        String key = internalBucket.getKey().toString();
        if(key.equalsIgnoreCase("b")) {
            Assert.assertEquals(2, count);
        }
        else {
            throw new Exception(String.format("Unexpected key. expected: only a . found: %s", key));
        }
    }
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:23,代码来源:AggregationTest.java

示例4: assertUnboundedDocCountError

import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入方法依赖的package包/类
private void assertUnboundedDocCountError(int size, SearchResponse accurateResponse, SearchResponse testResponse) {
    Terms accurateTerms = accurateResponse.getAggregations().get("terms");
    assertThat(accurateTerms, notNullValue());
    assertThat(accurateTerms.getName(), equalTo("terms"));
    assertThat(accurateTerms.getDocCountError(), equalTo(0L));

    Terms testTerms = testResponse.getAggregations().get("terms");
    assertThat(testTerms, notNullValue());
    assertThat(testTerms.getName(), equalTo("terms"));
    assertThat(testTerms.getDocCountError(),anyOf(equalTo(-1L), equalTo(0L)));
    Collection<Bucket> testBuckets = testTerms.getBuckets();
    assertThat(testBuckets.size(), lessThanOrEqualTo(size));
    assertThat(accurateTerms.getBuckets().size(), greaterThanOrEqualTo(testBuckets.size()));

    for (Terms.Bucket testBucket : testBuckets) {
        assertThat(testBucket, notNullValue());
        Terms.Bucket accurateBucket = accurateTerms.getBucketByKey(testBucket.getKeyAsString());
        assertThat(accurateBucket, notNullValue());
        assertThat(accurateBucket.getDocCountError(), equalTo(0L));
        assertThat(testBucket.getDocCountError(), anyOf(equalTo(-1L), equalTo(0L)));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:TermsDocCountErrorIT.java

示例5: groupByOnNestedFieldTest

import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入方法依赖的package包/类
@Test
public void groupByOnNestedFieldTest() throws Exception {
    Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/nestedType GROUP BY nested(message.info)", TEST_INDEX));
    InternalNested nested = result.get("[email protected]");
    Terms infos = nested.getAggregations().get("message.info");
    Assert.assertEquals(3,infos.getBuckets().size());
    for(Terms.Bucket bucket : infos.getBuckets()) {
        String key = bucket.getKey().toString();
        long count = ((ValueCount) bucket.getAggregations().get("COUNT(*)")).getValue();
        if(key.equalsIgnoreCase("a")) {
            Assert.assertEquals(2, count);
        }
        else if(key.equalsIgnoreCase("c")) {
            Assert.assertEquals(2, count);
        }
        else if(key.equalsIgnoreCase("b")) {
            Assert.assertEquals(1, count);
        }
        else {
            throw new Exception(String.format("Unexpected key. expected: a OR b OR c . found: %s", key));
        }
    }
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:24,代码来源:AggregationTest.java

示例6: groupByTestWithFilter

import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入方法依赖的package包/类
@Test
public void groupByTestWithFilter() throws Exception {
    Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/account GROUP BY filter(gender='m'),gender", TEST_INDEX));
    InternalFilter filter = result.get("filter(gender = 'm')@FILTER");
    Terms gender = filter.getAggregations().get("gender");

    for(Terms.Bucket bucket : gender.getBuckets()) {
        String key = bucket.getKey().toString();
        long count = ((ValueCount) bucket.getAggregations().get("COUNT(*)")).getValue();
        if(key.equalsIgnoreCase("m")) {
            Assert.assertEquals(507, count);
        }
        else {
            throw new Exception(String.format("Unexpected key. expected: only m. found: %s", key));
        }
    }
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:18,代码来源:AggregationTest.java

示例7: groupByTest

import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入方法依赖的package包/类
@Test
public void groupByTest() throws Exception {
	Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/account GROUP BY gender", TEST_INDEX));
	Terms gender = result.get("gender");
	for(Terms.Bucket bucket : gender.getBuckets()) {
		String key = bucket.getKey().toString();
		long count = ((ValueCount) bucket.getAggregations().get("COUNT(*)")).getValue();
		if(key.equalsIgnoreCase("m")) {
			Assert.assertEquals(507, count);
		}
		else if(key.equalsIgnoreCase("f")) {
			Assert.assertEquals(493, count);
		}
		else {
			throw new Exception(String.format("Unexpected key. expected: m OR f. found: %s", key));
		}
	}
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:19,代码来源:AggregationTest.java

示例8: assertEquals

import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入方法依赖的package包/类
private void assertEquals(Terms t1, Terms t2) {
    List<Terms.Bucket> t1Buckets = t1.getBuckets();
    List<Terms.Bucket> t2Buckets = t1.getBuckets();
    assertEquals(t1Buckets.size(), t2Buckets.size());
    for (Iterator<Terms.Bucket> it1 = t1Buckets.iterator(), it2 = t2Buckets.iterator(); it1.hasNext(); ) {
        final Terms.Bucket b1 = it1.next();
        final Terms.Bucket b2 = it2.next();
        assertEquals(b1.getDocCount(), b2.getDocCount());
        assertEquals(b1.getKey(), b2.getKey());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:EquivalenceIT.java

示例9: generateBinaryMatrix

import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入方法依赖的package包/类
/**
 * Method to generate a binary user*query matrix (stored in temporary .csv
 * file)
 */
public void generateBinaryMatrix() {
  try {

    System.out.println(props.getProperty("userHistoryMatrix"));
    File file = new File(props.getProperty("userHistoryMatrix"));
    if (file.exists()) {
      file.delete();
    }

    file.createNewFile();

    FileWriter fw = new FileWriter(file.getAbsoluteFile());
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write("Num" + ",");

    // step 1: write first row of csv
    List<String> logIndexList = es.getIndexListWithPrefix(props.getProperty(MudrodConstants.LOG_INDEX));

    String[] logIndices = logIndexList.toArray(new String[0]);
    String[] statictypeArray = new String[] { this.sessionStats };
    int docCount = es.getDocCount(logIndices, statictypeArray);

    SearchResponse sr = es.getClient().prepareSearch(logIndices).setTypes(statictypeArray).setQuery(QueryBuilders.matchAllQuery()).setSize(0)
        .addAggregation(AggregationBuilders.terms("IPs").field("IP").size(docCount)).execute().actionGet();
    Terms ips = sr.getAggregations().get("IPs");
    List<String> ipList = new ArrayList<>();
    for (Terms.Bucket entry : ips.getBuckets()) {
      if (entry.getDocCount() > Integer.parseInt(props.getProperty(MudrodConstants.MINI_USER_HISTORY))) { // filter
        // out
        // less
        // active users/ips
        ipList.add(entry.getKey().toString());
      }
    }
    bw.write(String.join(",", ipList) + "\n");

    // step 2: step the rest rows of csv
    SearchRequestBuilder sr2Builder = es.getClient().prepareSearch(logIndices).setTypes(statictypeArray).setQuery(QueryBuilders.matchAllQuery()).setSize(0)
        .addAggregation(AggregationBuilders.terms("KeywordAgg").field("keywords").size(docCount).subAggregation(AggregationBuilders.terms("IPAgg").field("IP").size(docCount)));

    SearchResponse sr2 = sr2Builder.execute().actionGet();
    Terms keywords = sr2.getAggregations().get("KeywordAgg");

    for (Terms.Bucket keyword : keywords.getBuckets()) {

      Map<String, Integer> ipMap = new HashMap<>();
      Terms ipAgg = keyword.getAggregations().get("IPAgg");

      int distinctUser = ipAgg.getBuckets().size();
      if (distinctUser > Integer.parseInt(props.getProperty(MudrodConstants.MINI_USER_HISTORY))) {
        bw.write(keyword.getKey() + ",");
        for (Terms.Bucket IP : ipAgg.getBuckets()) {

          ipMap.put(IP.getKey().toString(), 1);
        }
        for (int i = 0; i < ipList.size(); i++) {
          if (ipMap.containsKey(ipList.get(i))) {
            bw.write(ipMap.get(ipList.get(i)) + ",");
          } else {
            bw.write("0,");
          }
        }
        bw.write("\n");
      }
    }

    bw.close();
  } catch (IOException e) {
    e.printStackTrace();
  }

}
 
开发者ID:apache,项目名称:incubator-sdap-mudrod,代码行数:77,代码来源:HistoryGenerator.java

示例10: testIssue10719

import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入方法依赖的package包/类
public void testIssue10719() throws Exception {
    // Tests that we can refer to nested elements under a sample in a path
    // statement
    boolean asc = randomBoolean();
    SearchResponse response = client().prepareSearch("test").setTypes("book").setSearchType(SearchType.QUERY_THEN_FETCH)
            .addAggregation(terms("genres")
                    .field("genre")
                    .order(Terms.Order.aggregation("sample>max_price.value", asc))
                    .subAggregation(sampler("sample").shardSize(100)
                            .subAggregation(max("max_price").field("price")))
            ).execute().actionGet();
    assertSearchResponse(response);
    Terms genres = response.getAggregations().get("genres");
    Collection<Bucket> genreBuckets = genres.getBuckets();
    // For this test to be useful we need >1 genre bucket to compare
    assertThat(genreBuckets.size(), greaterThan(1));
    double lastMaxPrice = asc ? Double.MIN_VALUE : Double.MAX_VALUE;
    for (Terms.Bucket genreBucket : genres.getBuckets()) {
        Sampler sample = genreBucket.getAggregations().get("sample");
        Max maxPriceInGenre = sample.getAggregations().get("max_price");
        double price = maxPriceInGenre.getValue();
        if (asc) {
            assertThat(price, greaterThanOrEqualTo(lastMaxPrice));
        } else {
            assertThat(price, lessThanOrEqualTo(lastMaxPrice));
        }
        lastMaxPrice = price;
    }

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:DiversifiedSamplerIT.java

示例11: reverseAnotherNestedGroupByOnNestedFieldWithFilterTestWithReverseNestedOnHistogram

import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入方法依赖的package包/类
@Test
public void reverseAnotherNestedGroupByOnNestedFieldWithFilterTestWithReverseNestedOnHistogram() throws Exception {
    Aggregations result = query(String.format("SELECT COUNT(*) FROM %s/nestedType GROUP BY  nested(message.info),filter('myFilter',message.info = 'a'),histogram('field'='comment.likes','reverse_nested'='~comment','interval'='2' , 'alias' = 'someAlias' )", TEST_INDEX));
    InternalNested nested = result.get("[email protected]");
    InternalFilter filter = nested.getAggregations().get("[email protected]");
    Terms infos = filter.getAggregations().get("message.info");
    Assert.assertEquals(1,infos.getBuckets().size());
    for(Terms.Bucket bucket : infos.getBuckets()) {
        InternalReverseNested reverseNested = bucket.getAggregations().get("[email protected]_REVERSED");
        InternalNested innerNested = reverseNested.getAggregations().get("[email protected]");
        InternalHistogram histogram = innerNested.getAggregations().get("someAlias");
        Assert.assertEquals(2, histogram.getBuckets().size());

    }
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:16,代码来源:AggregationTest.java

示例12: processSessionInSequential

import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入方法依赖的package包/类
public void processSessionInSequential() throws IOException, InterruptedException, ExecutionException {
  es.createBulkProcessor();
  Terms Sessions = this.getSessionTerms();
  int session_count = 0;
  for (Terms.Bucket entry : Sessions.getBuckets()) {
    if (entry.getDocCount() >= 3 && !entry.getKey().equals("invalid")) {
      String sessionid = entry.getKey().toString();
      int sessionNum = processSession(es, sessionid);
      session_count += sessionNum;
    }
  }
  LOG.info("Final Session count: {}", Integer.toString(session_count));
  es.destroyBulkProcessor();
}
 
开发者ID:apache,项目名称:incubator-sdap-mudrod,代码行数:15,代码来源:SessionStatistic.java

示例13: testNestedAggs

import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入方法依赖的package包/类
public void testNestedAggs() throws Exception {
    String[][] expectedKeywordsByCategory={
            { "paul", "weller", "jam", "style", "council" },
            { "paul", "smith" },
            { "craig", "kelly", "terje", "haakonsen", "burton" }};
    SearchResponse response = client().prepareSearch("test")
            .setSearchType(SearchType.QUERY_THEN_FETCH)
            .addAggregation(terms("myCategories").field("fact_category").minDocCount(2)
                    .subAggregation(
                               significantTerms("mySignificantTerms").field("description")
                               .executionHint(randomExecutionHint())
                               .minDocCount(2)))
            .execute()
            .actionGet();
    assertSearchResponse(response);
    Terms topCategoryTerms = response.getAggregations().get("myCategories");
    for (org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket topCategory : topCategoryTerms.getBuckets()) {
        SignificantTerms topTerms = topCategory.getAggregations().get("mySignificantTerms");
        HashSet<String> foundTopWords = new HashSet<String>();
        for (Bucket topTerm : topTerms) {
            foundTopWords.add(topTerm.getKeyAsString());
        }
        String[] expectedKeywords = expectedKeywordsByCategory[Integer.parseInt(topCategory.getKeyAsString()) - 1];
        for (String expectedKeyword : expectedKeywords) {
            assertTrue(expectedKeyword + " missing from category keywords", foundTopWords.contains(expectedKeyword));
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:29,代码来源:SignificantTermsIT.java

示例14: reverseToRootGroupByOnNestedFieldWithFilterAndSumOnReverseNestedField

import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入方法依赖的package包/类
@Test
public void reverseToRootGroupByOnNestedFieldWithFilterAndSumOnReverseNestedField() throws Exception {
    Aggregations result = query(String.format("SELECT sum(reverse_nested(myNum)) bla FROM %s/nestedType GROUP BY  nested(message.info),filter('myFilter',message.info = 'a')", TEST_INDEX));
    InternalNested nested = result.get("[email protected]");
    InternalFilter filter = nested.getAggregations().get("[email protected]");
    Terms infos = filter.getAggregations().get("message.info");
    Assert.assertEquals(1,infos.getBuckets().size());
    for(Terms.Bucket bucket : infos.getBuckets()) {
        InternalReverseNested reverseNested = bucket.getAggregations().get("[email protected]");
        InternalSum sum = reverseNested.getAggregations().get("bla");
        Assert.assertEquals(5.0,sum.getValue(),0.000001);

    }
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:15,代码来源:AggregationTest.java

示例15: reverseAnotherNestedGroupByOnNestedFieldWithFilterAndSumOnReverseNestedField

import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入方法依赖的package包/类
@Test
public void reverseAnotherNestedGroupByOnNestedFieldWithFilterAndSumOnReverseNestedField() throws Exception {
    Aggregations result = query(String.format("SELECT sum(reverse_nested(comment.likes,'~comment')) bla FROM %s/nestedType GROUP BY  nested(message.info),filter('myFilter',message.info = 'a')", TEST_INDEX));
    InternalNested nested = result.get("[email protected]");
    InternalFilter filter = nested.getAggregations().get("[email protected]");
    Terms infos = filter.getAggregations().get("message.info");
    Assert.assertEquals(1,infos.getBuckets().size());
    for(Terms.Bucket bucket : infos.getBuckets()) {
        InternalReverseNested reverseNested = bucket.getAggregations().get("[email protected]_REVERSED");
        InternalNested innerNested = reverseNested.getAggregations().get("[email protected]");
        InternalSum sum = innerNested.getAggregations().get("bla");
        Assert.assertEquals(4.0,sum.getValue(),0.000001);

    }
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:16,代码来源:AggregationTest.java


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