df643f2368719bbb675a7c4d4cb13d4e1f086949
[aai/search-data-service.git] / src / main / java / org / onap / aai / sa / searchdbabstraction / searchapi / GroupByAggregation.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21 package org.onap.aai.sa.searchdbabstraction.searchapi;
22
23 /**
24  * An example of a date_range aggregation:
25  *
26  * <p><pre>
27  * {
28  *    "aggs": {
29  *        "my_group": {
30  *            "term": {
31  *                "field": "group"
32  *            }
33  *        }
34  *    }
35  * }
36  * </pre>
37  *
38  * @author sye
39  */
40 public class GroupByAggregation extends AbstractAggregation {
41
42   @Override
43   public String toElasticSearch() {
44     StringBuilder sb = new StringBuilder();
45
46     sb.append("\"terms\": {\"field\": \"");
47     sb.append(field);
48     sb.append("\"");
49     if (size != null) {
50       sb.append(", \"size\": ");
51       sb.append(size);
52     }
53
54     if (minThreshold != null) {
55       sb.append(", \"min_doc_count\": ").append(minThreshold);
56     }
57
58     sb.append("}");
59
60     return sb.toString();
61   }
62
63   @Override
64   public String toString() {
65     return "{group-by: {field: " + field + ", size: " + size
66         + " minThreshold: " + minThreshold + "}}";
67   }
68
69 }