Package org.elasticsearch.search.aggregations.bucket.terms

Examples of org.elasticsearch.search.aggregations.bucket.terms.Terms


      Collection<SearchItem> res = resultsService.prepareAll(response.getHits());

      if (response.getAggregations() != null) {
        Filter countFacet = response.getAggregations().get("sections");
        Terms sectionsFacet = countFacet.getAggregations().get("sections");

        if (sectionsFacet.getBuckets().size()>1) {
          params.put("sectionFacet", resultsService.buildSectionFacet(countFacet));

          if (!Strings.isNullOrEmpty(query.getSection()) && sectionsFacet.getBucketByKey(query.getSection())!=null) {
            Terms.Bucket selectedSection = sectionsFacet.getBucketByKey(query.getSection());

            params.put("groupFacet", resultsService.buildGroupFacet(selectedSection));
          }
        } else if (Strings.isNullOrEmpty(query.getSection()) && sectionsFacet.getBuckets().size()==1) {
          Terms.Bucket onlySection = sectionsFacet.getBuckets().iterator().next();
          query.setSection(onlySection.getKey());

          params.put("groupFacet", resultsService.buildGroupFacet(onlySection));
        }
View Full Code Here


        .size(Integer.MAX_VALUE)
        .minDocCount(0));

    SearchResponse response = request.get();

    Terms values =
      response.getAggregations().get(indexField.field());

    for (Terms.Bucket value : values.getBuckets()) {
      counts.put(value.getKey(), value.getDocCount());
    }
    return counts;
  }
View Full Code Here

      long docCount = missing.getDocCount();
      if (docCount > 0L) {
        this.facets.put(aggregation.getName().replace("_missing",""), new FacetValue("", docCount));
      }
    } else if (Terms.class.isAssignableFrom(aggregation.getClass())) {
      Terms termAggregation = (Terms) aggregation;
      for (Terms.Bucket value : termAggregation.getBuckets()) {
        this.facets.put(aggregation.getName().replace("_selected",""), new FacetValue(value.getKey(), value.getDocCount()));
      }
    } else if (HasAggregations.class.isAssignableFrom(aggregation.getClass())) {
      HasAggregations hasAggregations = (HasAggregations) aggregation;
      for (Aggregation internalAggregation : hasAggregations.getAggregations()) {
View Full Code Here

        .size(Integer.MAX_VALUE)
        .minDocCount(1));

    SearchResponse esResponse = request.get();

    Terms aggregation = esResponse.getAggregations().get(key);

    if (aggregation != null) {
      for (Terms.Bucket value : aggregation.getBuckets()) {
        tags.add(value.getKey());
      }
    }
    return tags;
  }
View Full Code Here

      .field(IssueNormalizer.IssueField.ASSIGNEE.field()));
    esSearch.addAggregation(AggregationBuilders.missing("notAssigned")
      .field(IssueNormalizer.IssueField.ASSIGNEE.field()));

    SearchResponse response = esSearch.get();
    Terms aggregation = (Terms) response.getAggregations().getAsMap().get(IssueNormalizer.IssueField.ASSIGNEE.field());
    List<FacetValue> facetValues = newArrayList();
    for (Terms.Bucket value : aggregation.getBuckets()) {
      facetValues.add(new FacetValue(value.getKey(), value.getDocCount()));
    }
    facetValues.add(new FacetValue("_notAssigned_", ((InternalMissing) response.getAggregations().get("notAssigned")).getDocCount()));

    return facetValues;
View Full Code Here

                .setSearchType(SearchType.COUNT)
                .setQuery(matchAllQuery())
                .addAggregation(terms("name").field("name"))
                .addAggregation(terms("not_filtered").field("not_filtered")).get();
        Aggregations aggs = searchResponse.getAggregations();
        Terms nameAgg = aggs.get("name");
        assertThat(nameAgg.getBuckets().size(), Matchers.equalTo(1));
        assertThat(nameAgg.getBuckets().iterator().next().getKey(), Matchers.equalTo("bacon"));
       
        Terms notFilteredAgg = aggs.get("not_filtered");
        assertThat(notFilteredAgg.getBuckets().size(), Matchers.equalTo(2));
        assertThat(notFilteredAgg.getBuckets().get(0).getKey(), Matchers.isOneOf("bacon", "bastards"));
        assertThat(notFilteredAgg.getBuckets().get(1).getKey(), Matchers.isOneOf("bacon", "bastards"));
    }
View Full Code Here

        searchResponse = client().prepareSearch("tests").setQuery(QueryBuilders.matchQuery("name", "bar"))
                .addAggregation(AggregationBuilders.global("global").subAggregation(AggregationBuilders.terms("test").field("name")))
                .get();
        assertSearchResponse(searchResponse);
        Global global = searchResponse.getAggregations().get("global");
        Terms terms = global.getAggregations().get("test");
        assertThat(terms.getBuckets().size(), equalTo(4));

        logger.info("--> checking single filtering alias search with global facets and sort");
        searchResponse = client().prepareSearch("tests").setQuery(QueryBuilders.matchQuery("name", "bar"))
                .addAggregation(AggregationBuilders.global("global").subAggregation(AggregationBuilders.terms("test").field("name")))
                .addSort("_uid", SortOrder.ASC).get();
        assertSearchResponse(searchResponse);
        global = searchResponse.getAggregations().get("global");
        terms = global.getAggregations().get("test");
        assertThat(terms.getBuckets().size(), equalTo(4));

        logger.info("--> checking single filtering alias search with non-global facets");
        searchResponse = client().prepareSearch("tests").setQuery(QueryBuilders.matchQuery("name", "bar"))
                .addAggregation(AggregationBuilders.terms("test").field("name"))
                .addSort("_uid", SortOrder.ASC).get();
        assertSearchResponse(searchResponse);
        terms = searchResponse.getAggregations().get("test");
        assertThat(terms.getBuckets().size(), equalTo(2));

        searchResponse = client().prepareSearch("foos", "bars").setQuery(QueryBuilders.matchAllQuery()).get();
        assertHits(searchResponse.getHits(), "1", "2");

        logger.info("--> checking single non-filtering alias search");
View Full Code Here

                    .addAggregation(
                            terms("myterms")
                                    .size(AGG_SIZE)
                                    .field("num")
                    ).setSearchType(SearchType.COUNT).get();
            Terms terms = resp.getAggregations().get("myterms");
            assertNotNull("term aggs were calculated", terms);
            totalTime += resp.getTookInMillis();
        }

        System.out.println("--> single threaded average time: " + (totalTime / QUERIES) + "ms");
View Full Code Here

                                .addAggregation(
                                        terms("myterms")
                                                .size(AGG_SIZE)
                                                .field("num")
                                ).setSearchType(SearchType.COUNT).get();
                        Terms terms = resp.getAggregations().get("myterms");
                        assertNotNull("term aggs were calculated", terms);
                        totalThreadedTime.addAndGet(resp.getTookInMillis());
                    }
                }
            });
View Full Code Here

                        .addAggregation(
                                terms("myterms")
                                        .size(AGG_SIZE)
                                        .field("num")
                        ).setSearchType(SearchType.COUNT).get();
                Terms terms = resp.getAggregations().get("myterms");
                assertNotNull("term aggs were calculated", terms);
            }

            System.out.println("--> running single-threaded tests");
            runSingleThreadedQueries(client);
View Full Code Here

TOP

Related Classes of org.elasticsearch.search.aggregations.bucket.terms.Terms

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.