本文整理汇总了Java中org.elasticsearch.search.aggregations.bucket.terms.Terms类的典型用法代码示例。如果您正苦于以下问题:Java Terms类的具体用法?Java Terms怎么用?Java Terms使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Terms类属于org.elasticsearch.search.aggregations.bucket.terms包,在下文中一共展示了Terms类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testScriptScore
import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入依赖的package包/类
public void testScriptScore() throws ExecutionException, InterruptedException, IOException {
indexRandomFrequencies01(randomBoolean() ? "text" : "long");
ScriptHeuristic scriptHeuristic = getScriptSignificanceHeuristic();
SearchResponse response = client().prepareSearch(INDEX_NAME)
.addAggregation(terms("class").field(CLASS_FIELD)
.subAggregation(significantTerms("mySignificantTerms")
.field(TEXT_FIELD)
.executionHint(randomExecutionHint())
.significanceHeuristic(scriptHeuristic)
.minDocCount(1).shardSize(2).size(2)))
.execute()
.actionGet();
assertSearchResponse(response);
for (Terms.Bucket classBucket : ((Terms) response.getAggregations().get("class")).getBuckets()) {
SignificantTerms sigTerms = classBucket.getAggregations().get("mySignificantTerms");
for (SignificantTerms.Bucket bucket : sigTerms.getBuckets()) {
assertThat(bucket.getSignificanceScore(),
is((double) bucket.getSubsetDf() + bucket.getSubsetSize() + bucket.getSupersetDf() + bucket.getSupersetSize()));
}
}
}
示例2: testFromSizeWithAggregations
import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入依赖的package包/类
@Test
public void testFromSizeWithAggregations() throws Exception {
final String query1 = String.format("SELECT /*! DOCS_WITH_AGGREGATION(0,1) */" +
" account_number FROM %s/account GROUP BY gender", TEST_INDEX);
SearchResponse response1 = (SearchResponse) getSearchRequestBuilder(query1).get();
Assert.assertEquals(1, response1.getHits().getHits().length);
Terms gender1 = response1.getAggregations().get("gender");
Assert.assertEquals(2, gender1.getBuckets().size());
Object account1 = response1.getHits().getHits()[0].getSource().get("account_number");
final String query2 = String.format("SELECT /*! DOCS_WITH_AGGREGATION(1,1) */" +
" account_number FROM %s/account GROUP BY gender", TEST_INDEX);
SearchResponse response2 = (SearchResponse) getSearchRequestBuilder(query2).get();
Assert.assertEquals(1, response2.getHits().getHits().length);
Terms gender2 = response2.getAggregations().get("gender");
Assert.assertEquals(2, gender2.getBuckets().size());
Object account2 = response2.getHits().getHits()[0].getSource().get("account_number");
Assert.assertEquals(response1.getHits().getTotalHits(), response2.getHits().getTotalHits());
Assert.assertNotEquals(account1, account2);
}
示例3: testSingleValuedFieldOrderedByMissingSubAggregation
import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入依赖的package包/类
public void testSingleValuedFieldOrderedByMissingSubAggregation() throws Exception {
for (String index : Arrays.asList("idx", "idx_unmapped")) {
try {
client().prepareSearch(index)
.setTypes("type")
.addAggregation(
terms("terms").executionHint(randomExecutionHint()).field(SINGLE_VALUED_FIELD_NAME)
.collectMode(randomFrom(SubAggCollectionMode.values()))
.order(Terms.Order.aggregation("avg_i", true))).execute().actionGet();
fail("Expected search to fail when trying to sort terms aggregation by sug-aggregation that doesn't exist");
} catch (ElasticsearchException e) {
// expected
}
}
}
示例4: testSingleValuedFieldOrderedByNonMetricsOrMultiBucketSubAggregation
import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入依赖的package包/类
public void testSingleValuedFieldOrderedByNonMetricsOrMultiBucketSubAggregation() throws Exception {
for (String index : Arrays.asList("idx", "idx_unmapped")) {
try {
client().prepareSearch(index)
.setTypes("type")
.addAggregation(
terms("terms").executionHint(randomExecutionHint()).field(SINGLE_VALUED_FIELD_NAME)
.collectMode(randomFrom(SubAggCollectionMode.values()))
.order(Terms.Order.aggregation("values", true))
.subAggregation(terms("values").field("i").collectMode(randomFrom(SubAggCollectionMode.values()))))
.execute().actionGet();
fail("Expected search to fail when trying to sort terms aggregation by sug-aggregation " +
"which is not of a metrics or single-bucket type");
} catch (ElasticsearchException e) {
// expected
}
}
}
示例5: testSingleValuedFieldOrderedByMultiValuedSubAggregationWithUknownMetric
import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入依赖的package包/类
public void testSingleValuedFieldOrderedByMultiValuedSubAggregationWithUknownMetric() throws Exception {
for (String index : Arrays.asList("idx", "idx_unmapped")) {
try {
SearchResponse response = client()
.prepareSearch(index)
.setTypes("type")
.addAggregation(
terms("terms").executionHint(randomExecutionHint()).field(SINGLE_VALUED_FIELD_NAME)
.collectMode(randomFrom(SubAggCollectionMode.values()))
.order(Terms.Order.aggregation("stats.foo", true)).subAggregation(stats("stats").field("i")))
.execute().actionGet();
fail("Expected search to fail when trying to sort terms aggregation by multi-valued sug-aggregation "
+ "with an unknown specified metric to order by. response had " + response.getFailedShards() + " failed shards.");
} catch (ElasticsearchException e) {
// expected
}
}
}
示例6: 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));
}
}
示例7: 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)));
}
}
示例8: testSingleValuedFieldOrderedByMissingSubAggregation
import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入依赖的package包/类
public void testSingleValuedFieldOrderedByMissingSubAggregation() throws Exception {
for (String index : Arrays.asList("idx", "idx_unmapped")) {
try {
client().prepareSearch(index)
.setTypes("type")
.addAggregation(
terms("terms").field(SINGLE_VALUED_FIELD_NAME).collectMode(randomFrom(SubAggCollectionMode.values()))
.order(Terms.Order.aggregation("avg_i", true))).execute().actionGet();
fail("Expected search to fail when trying to sort terms aggregation by sug-aggregation that doesn't exist");
} catch (ElasticsearchException e) {
// expected
}
}
}
示例9: testSingleValuedFieldOrderedByNonMetricsOrMultiBucketSubAggregation
import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入依赖的package包/类
public void testSingleValuedFieldOrderedByNonMetricsOrMultiBucketSubAggregation() throws Exception {
for (String index : Arrays.asList("idx", "idx_unmapped")) {
try {
client().prepareSearch(index)
.setTypes("type")
.addAggregation(
terms("terms")
.field(SINGLE_VALUED_FIELD_NAME)
.collectMode(randomFrom(SubAggCollectionMode.values()))
.order(Terms.Order.aggregation("num_tags", true))
.subAggregation(
terms("num_tags").field("num_tags").collectMode(randomFrom(SubAggCollectionMode.values()))))
.execute().actionGet();
fail("Expected search to fail when trying to sort terms aggregation by sug-aggregation which is not of a metrics type");
} catch (ElasticsearchException e) {
// expected
}
}
}
示例10: checkByRateInSequential
import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入依赖的package包/类
/**
* Check crawler by request sending rate, which is read from configruation
* file
*
* @throws InterruptedException InterruptedException
* @throws IOException IOException
*/
public void checkByRateInSequential() throws InterruptedException, IOException {
es.createBulkProcessor();
int rate = Integer.parseInt(props.getProperty("sendingrate"));
Terms users = this.getUserTerms(this.httpType);
LOG.info("Original User count: {}", Integer.toString(users.getBuckets().size()));
int userCount = 0;
for (Terms.Bucket entry : users.getBuckets()) {
String user = entry.getKey().toString();
int count = checkByRate(es, user);
userCount += count;
}
es.destroyBulkProcessor();
LOG.info("User count: {}", Integer.toString(userCount));
}
示例11: testSingleValuedFieldOrderedByMultiValuedSubAggregationWithoutMetric
import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入依赖的package包/类
public void testSingleValuedFieldOrderedByMultiValuedSubAggregationWithoutMetric() throws Exception {
for (String index : Arrays.asList("idx", "idx_unmapped")) {
try {
client().prepareSearch(index)
.setTypes("type")
.addAggregation(
terms("terms").field(SINGLE_VALUED_FIELD_NAME).collectMode(randomFrom(SubAggCollectionMode.values()))
.order(Terms.Order.aggregation("stats", true))
.subAggregation(stats("stats").field(SINGLE_VALUED_FIELD_NAME))).execute().actionGet();
fail("Expected search to fail when trying to sort terms aggregation by multi-valued sug-aggregation " +
"where the metric name is not specified");
} catch (ElasticsearchException e) {
// expected
}
}
}
示例12: assertSubset
import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入依赖的package包/类
private void assertSubset(Terms terms1, Terms terms2, long minDocCount, int size, String include) {
final Matcher matcher = include == null ? null : Pattern.compile(include).matcher("");;
final Iterator<Terms.Bucket> it1 = terms1.getBuckets().iterator();
final Iterator<Terms.Bucket> it2 = terms2.getBuckets().iterator();
int size2 = 0;
while (it1.hasNext()) {
final Terms.Bucket bucket1 = it1.next();
if (bucket1.getDocCount() >= minDocCount && (matcher == null || matcher.reset(bucket1.getKeyAsString()).matches())) {
if (size2++ == size) {
break;
}
assertTrue("minDocCount: " + minDocCount, it2.hasNext());
final Terms.Bucket bucket2 = it2.next();
assertEquals("minDocCount: " + minDocCount, bucket1.getDocCount(), bucket2.getDocCount());
}
}
assertFalse(it2.hasNext());
}
示例13: 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));
}
}
}
示例14: testDiversifiedSampler_noDocs
import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入依赖的package包/类
public void testDiversifiedSampler_noDocs() throws Exception {
Directory directory = newDirectory();
RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
indexWriter.close();
IndexReader indexReader = DirectoryReader.open(directory);
IndexSearcher indexSearcher = new IndexSearcher(indexReader);
MappedFieldType idFieldType = new KeywordFieldMapper.KeywordFieldType();
idFieldType.setName("id");
idFieldType.setHasDocValues(true);
MappedFieldType genreFieldType = new KeywordFieldMapper.KeywordFieldType();
genreFieldType.setName("genre");
genreFieldType.setHasDocValues(true);
DiversifiedAggregationBuilder builder = new DiversifiedAggregationBuilder("_name")
.field(genreFieldType.name())
.subAggregation(new TermsAggregationBuilder("terms", null).field("id"));
InternalSampler result = search(indexSearcher, new MatchAllDocsQuery(), builder, genreFieldType, idFieldType);
Terms terms = result.getAggregations().get("terms");
assertEquals(0, terms.getBuckets().size());
indexReader.close();
directory.close();
}
示例15: mapResults
import org.elasticsearch.search.aggregations.bucket.terms.Terms; //导入依赖的package包/类
@Override
public <T> FacetedPageImpl<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
Aggregations aggregations = response.getAggregations();
Terms agg = aggregations.get(term) ;
long total = agg.getSumOfOtherDocCounts() ;
List<T> results = new ArrayList<T>();
if(agg.getBuckets()!=null && agg.getBuckets().size()>0){
for (Terms.Bucket entry : agg.getBuckets()) {
if(!StringUtils.isBlank(name) && entry.getAggregations().get(name)!=null){
TopHits topHits = entry.getAggregations().get(name);
for (SearchHit hit : topHits.getHits().getHits()) {
T data = mapEntity(hit.getSourceAsString() , hit , clazz) ;
if(data instanceof UKAgg){
((UKAgg) data).setRowcount((int) topHits.getHits().getTotalHits());
}
results.add(data) ;
}
}
}
}
return new FacetedPageImpl<T>(results, pageable, total);
}