String timeZoneString = tzFormat.format(now);
Interval bucketSize = Interval.YEAR;
- long startTime = query.createdAfter() == null ? getMinCreatedAt(filters, esQuery) : query.createdAfter().getTime();
- long endTime = query.createdBefore() == null ? now.getTime() : query.createdBefore().getTime();
+ Date createdAfter = query.createdAfter();
+ long startTime = createdAfter == null ? getMinCreatedAt(filters, esQuery) : createdAfter.getTime();
+ Date createdBefore = query.createdBefore();
+ long endTime = createdBefore == null ? now.getTime() : createdBefore.getTime();
Duration timeSpan = new Duration(startTime, endTime);
if (timeSpan.isShorterThan(TWENTY_DAYS)) {
bucketSize = Interval.DAY;
setQueryFilter(minCount, esQuery, filters);
minCount.addAggregation(AggregationBuilders.min(facetNameAndField).field(facetNameAndField));
Min minValue = minCount.get().getAggregations().get(facetNameAndField);
- return Double.valueOf(minValue.getValue()).longValue();
+ return (long) minValue.getValue();
}
private void setSorting(IssueQuery query, SearchRequestBuilder esRequest) {
private void processAggregation(Aggregation aggregation) {
if (Missing.class.isAssignableFrom(aggregation.getClass())) {
- Missing missing = (Missing) aggregation;
- long docCount = missing.getDocCount();
- if (docCount > 0L) {
- this.facets.put(aggregation.getName().replace("_missing",""), new FacetValue("", docCount));
- }
+ processMissingAggregation(aggregation);
} else if (Terms.class.isAssignableFrom(aggregation.getClass())) {
- Terms termAggregation = (Terms) aggregation;
- for (Terms.Bucket value : termAggregation.getBuckets()) {
- String facetName = aggregation.getName();
- if (facetName.contains("__") && !facetName.startsWith("__")) {
- facetName = facetName.substring(0, facetName.indexOf("__"));
- }
- facetName = facetName.replace("_selected", "");
- this.facets.put(facetName, new FacetValue(value.getKey(), value.getDocCount()));
- }
+ processTermsAggregation(aggregation);
} else if (HasAggregations.class.isAssignableFrom(aggregation.getClass())) {
- HasAggregations hasAggregations = (HasAggregations) aggregation;
- for (Aggregation internalAggregation : hasAggregations.getAggregations()) {
- this.processAggregation(internalAggregation);
- }
+ processSubAggregations(aggregation);
} else if (DateHistogram.class.isAssignableFrom(aggregation.getClass())) {
- DateHistogram dateHistogram = (DateHistogram) aggregation;
- for (DateHistogram.Bucket value : dateHistogram.getBuckets()) {
- this.facets.put(dateHistogram.getName(), new FacetValue(value.getKeyAsText().toString(), value.getDocCount()));
- }
+ processDateHistogram(aggregation);
} else {
LOGGER.warn("Cannot process {} type of aggregation", aggregation.getClass());
}
}
+ private void processMissingAggregation(Aggregation aggregation) {
+ Missing missing = (Missing) aggregation;
+ long docCount = missing.getDocCount();
+ if (docCount > 0L) {
+ this.facets.put(aggregation.getName().replace("_missing",""), new FacetValue("", docCount));
+ }
+ }
+
+ private void processTermsAggregation(Aggregation aggregation) {
+ Terms termAggregation = (Terms) aggregation;
+ for (Terms.Bucket value : termAggregation.getBuckets()) {
+ String facetName = aggregation.getName();
+ if (facetName.contains("__") && !facetName.startsWith("__")) {
+ facetName = facetName.substring(0, facetName.indexOf("__"));
+ }
+ facetName = facetName.replace("_selected", "");
+ this.facets.put(facetName, new FacetValue(value.getKey(), value.getDocCount()));
+ }
+ }
+
+ private void processSubAggregations(Aggregation aggregation) {
+ HasAggregations hasAggregations = (HasAggregations) aggregation;
+ for (Aggregation internalAggregation : hasAggregations.getAggregations()) {
+ this.processAggregation(internalAggregation);
+ }
+ }
+
+ private void processDateHistogram(Aggregation aggregation) {
+ DateHistogram dateHistogram = (DateHistogram) aggregation;
+ for (DateHistogram.Bucket value : dateHistogram.getBuckets()) {
+ this.facets.put(dateHistogram.getName(), new FacetValue(value.getKeyAsText().toString(), value.getDocCount()));
+ }
+ }
+
public Iterator<K> scroll() {
Preconditions.checkState(scrollId != null, "Result is not scrollable. Please use QueryOptions.setScroll()");
return index.scroll(scrollId);