2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.sa.searchdbabstraction.searchapi;
25 import com.fasterxml.jackson.annotation.JsonProperty;
28 * An example of a date_range aggregation:
38 * { "to": "now-10M/M" },
39 * { "from": "now-10M/M" }
49 public class DateRangeAggregation extends AbstractAggregation {
52 private String format;
54 @JsonProperty("ranges")
55 private DateRange[] dateRanges;
58 public String getFormat() {
62 public void setFormat(String format) {
66 public DateRange[] getDateRanges() {
70 public void setDateRanges(DateRange[] dateRanges) {
71 this.dateRanges = dateRanges;
75 public String toElasticSearch() {
76 StringBuilder sb = new StringBuilder();
78 sb.append("\"date_range\": {\"field\": \"");
83 sb.append(", \"format\": \"");
88 if (dateRanges != null && dateRanges.length > 0) {
89 sb.append(", \"ranges\": [");
91 for (int i = 0; i < dateRanges.length; i++) {
95 sb.append(dateRanges[i].toElasticSearch());
102 sb.append(", \"size\": ");
106 if (minThreshold != null) {
107 sb.append(", \"min_doc_count\": ").append(minThreshold);
112 return sb.toString();
116 public String toString() {
117 StringBuffer sb = new StringBuffer();
118 sb.append("date-range: {field: " + field + ", format: " + format + ", size: " + size
119 + ", minThreshold: " + minThreshold + "ranges: [");
120 for (int i = 0; i < dateRanges.length; i++) {
124 sb.append(dateRanges[i].toString());
128 return sb.toString();