|
1 | 1 | package org.nlpcn.es4sql.query.maker;
|
2 | 2 |
|
| 3 | +import java.io.IOException; |
3 | 4 | import java.math.BigDecimal;
|
4 | 5 | import java.time.ZoneOffset;
|
5 | 6 | import java.util.*;
|
6 | 7 |
|
| 8 | +import org.elasticsearch.common.xcontent.NamedXContentRegistry; |
| 9 | +import org.elasticsearch.common.xcontent.XContentParser; |
| 10 | +import org.elasticsearch.common.xcontent.json.JsonXContent; |
7 | 11 | import org.elasticsearch.join.aggregations.JoinAggregationBuilders;
|
8 | 12 | import org.elasticsearch.script.Script;
|
9 | 13 | import org.elasticsearch.script.ScriptType;
|
|
17 | 21 | import org.elasticsearch.search.aggregations.bucket.nested.ReverseNestedAggregationBuilder;
|
18 | 22 | import org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder;
|
19 | 23 | import org.elasticsearch.search.aggregations.bucket.range.DateRangeAggregationBuilder;
|
| 24 | +import org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude; |
20 | 25 | import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
|
21 | 26 | import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBoundsAggregationBuilder;
|
22 | 27 | import org.elasticsearch.search.aggregations.metrics.percentiles.PercentilesAggregationBuilder;
|
@@ -253,6 +258,7 @@ private AggregationBuilder termsAgg(MethodField field) throws SqlParseException
|
253 | 258 | String aggName = gettAggNameFromParamsOrAlias(field);
|
254 | 259 | TermsAggregationBuilder terms = AggregationBuilders.terms(aggName);
|
255 | 260 | String value = null;
|
| 261 | + IncludeExclude include = null, exclude = null; |
256 | 262 | for (KVValue kv : field.getParams()) {
|
257 | 263 | value = kv.value.toString();
|
258 | 264 | switch (kv.key.toLowerCase()) {
|
@@ -288,10 +294,27 @@ private AggregationBuilder termsAgg(MethodField field) throws SqlParseException
|
288 | 294 | case "execution_hint":
|
289 | 295 | terms.executionHint(value);
|
290 | 296 | break;
|
| 297 | + case "include": |
| 298 | + try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, value)) { |
| 299 | + parser.nextToken(); |
| 300 | + include = IncludeExclude.parseInclude(parser); |
| 301 | + } catch (IOException e) { |
| 302 | + throw new SqlParseException("parse include[" + value + "] error: " + e.getMessage()); |
| 303 | + } |
| 304 | + break; |
| 305 | + case "exclude": |
| 306 | + try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY, value)) { |
| 307 | + parser.nextToken(); |
| 308 | + exclude = IncludeExclude.parseExclude(parser); |
| 309 | + } catch (IOException e) { |
| 310 | + throw new SqlParseException("parse exclude[" + value + "] error: " + e.getMessage()); |
| 311 | + } |
| 312 | + break; |
291 | 313 | default:
|
292 | 314 | throw new SqlParseException("terms aggregation err or not define field " + kv.toString());
|
293 | 315 | }
|
294 | 316 | }
|
| 317 | + terms.includeExclude(IncludeExclude.merge(include, exclude)); |
295 | 318 | return terms;
|
296 | 319 | }
|
297 | 320 |
|
|
0 commit comments