2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 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 package org.onap.aai.sa.searchdbabstraction.searchapi;
23 import com.fasterxml.jackson.annotation.JsonProperty;
26 * An example of a date_range aggregation:
36 * { "to": "now-10M/M" },
37 * { "from": "now-10M/M" }
47 public class DateRangeAggregation extends AbstractAggregation {
50 private String format;
52 @JsonProperty("ranges")
53 private DateRange[] dateRanges;
56 public String getFormat() {
60 public void setFormat(String format) {
64 public DateRange[] getDateRanges() {
68 public void setDateRanges(DateRange[] dateRanges) {
69 this.dateRanges = dateRanges;
73 public String toElasticSearch() {
74 StringBuilder sb = new StringBuilder();
76 sb.append("\"date_range\": {\"field\": \"");
81 sb.append(", \"format\": \"");
86 if (dateRanges != null && dateRanges.length > 0) {
87 sb.append(", \"ranges\": [");
89 for (int i = 0; i < dateRanges.length; i++) {
93 sb.append(dateRanges[i].toElasticSearch());
100 sb.append(", \"size\": ");
104 if (minThreshold != null) {
105 sb.append(", \"min_doc_count\": ").append(minThreshold);
110 return sb.toString();
114 public String toString() {
115 StringBuffer sb = new StringBuffer();
116 sb.append("date-range: {field: " + field + ", format: " + format + ", size: " + size
117 + ", minThreshold: " + minThreshold + "ranges: [");
118 for (int i = 0; i < dateRanges.length; i++) {
122 sb.append(dateRanges[i].toString());
126 return sb.toString();