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:
38 * { "to": "now-10M/M" },
39 * { "from": "now-10M/M" }
49 public class DateRangeAggregation extends AbstractAggregation {
51 private String format;
53 @JsonProperty("ranges")
54 private DateRange[] dateRanges;
57 public String getFormat() {
61 public void setFormat(String format) {
65 public DateRange[] getDateRanges() {
69 public void setDateRanges(DateRange[] dateRanges) {
70 this.dateRanges = dateRanges;
74 public String toElasticSearch() {
75 StringBuilder sb = new StringBuilder();
77 sb.append("\"date_range\": {\"field\": \"");
82 sb.append(", \"format\": \"");
87 if (dateRanges != null && dateRanges.length > 0) {
88 sb.append(", \"ranges\": [");
90 for (int i = 0; i < dateRanges.length; i++) {
94 sb.append(dateRanges[i].toElasticSearch());
101 sb.append(", \"size\": ");
105 if (minThreshold != null) {
106 sb.append(", \"min_doc_count\": ").append(minThreshold);
111 return sb.toString();
115 public String toString() {
116 StringBuilder sb = new StringBuilder();
117 sb.append("date-range: {field: " + field + ", format: " + format + ", size: " + size + ", minThreshold: "
118 + minThreshold + "ranges: [");
119 for (int i = 0; i < dateRanges.length; i++) {
123 sb.append(dateRanges[i].toString());
127 return sb.toString();