|
30 | 30 | import org.apache.lucene.util.BytesRef;
|
31 | 31 | import org.elasticsearch.common.ParseField;
|
32 | 32 | import org.elasticsearch.common.lease.Releasable;
|
| 33 | +import org.elasticsearch.common.logging.DeprecationLogger; |
| 34 | +import org.elasticsearch.common.logging.Loggers; |
33 | 35 | import org.elasticsearch.common.lucene.index.FilterableTermsEnum;
|
34 | 36 | import org.elasticsearch.common.lucene.index.FreqTermsEnum;
|
35 | 37 | import org.elasticsearch.index.mapper.MappedFieldType;
|
|
53 | 55 | import org.elasticsearch.search.internal.SearchContext;
|
54 | 56 |
|
55 | 57 | import java.io.IOException;
|
56 |
| -import java.util.Arrays; |
57 | 58 | import java.util.List;
|
58 | 59 | import java.util.Map;
|
59 | 60 |
|
60 | 61 | public class SignificantTermsAggregatorFactory extends ValuesSourceAggregatorFactory<ValuesSource, SignificantTermsAggregatorFactory>
|
61 | 62 | implements Releasable {
|
| 63 | + private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(Loggers.getLogger(SignificantTermsAggregatorFactory.class)); |
62 | 64 |
|
63 | 65 | private final IncludeExclude includeExclude;
|
64 | 66 | private final String executionHint;
|
@@ -202,17 +204,13 @@ protected Aggregator doCreateInternal(ValuesSource valuesSource, Aggregator pare
|
202 | 204 | if (valuesSource instanceof ValuesSource.Bytes) {
|
203 | 205 | ExecutionMode execution = null;
|
204 | 206 | if (executionHint != null) {
|
205 |
| - execution = ExecutionMode.fromString(executionHint); |
| 207 | + execution = ExecutionMode.fromString(executionHint, DEPRECATION_LOGGER); |
206 | 208 | }
|
207 |
| - if (!(valuesSource instanceof ValuesSource.Bytes.WithOrdinals)) { |
| 209 | + if (valuesSource instanceof ValuesSource.Bytes.WithOrdinals == false) { |
208 | 210 | execution = ExecutionMode.MAP;
|
209 | 211 | }
|
210 | 212 | if (execution == null) {
|
211 |
| - if (Aggregator.descendsFromBucketAggregator(parent)) { |
212 |
| - execution = ExecutionMode.GLOBAL_ORDINALS_HASH; |
213 |
| - } else { |
214 |
| - execution = ExecutionMode.GLOBAL_ORDINALS; |
215 |
| - } |
| 213 | + execution = ExecutionMode.GLOBAL_ORDINALS; |
216 | 214 | }
|
217 | 215 | assert execution != null;
|
218 | 216 |
|
@@ -291,44 +289,35 @@ Aggregator create(String name,
|
291 | 289 | Map<String, Object> metaData) throws IOException {
|
292 | 290 |
|
293 | 291 | final IncludeExclude.OrdinalsFilter filter = includeExclude == null ? null : includeExclude.convertToOrdinalsFilter(format);
|
| 292 | + boolean remapGlobalOrd = true; |
| 293 | + if (Aggregator.descendsFromBucketAggregator(parent) == false && |
| 294 | + factories == AggregatorFactories.EMPTY && |
| 295 | + includeExclude == null) { |
| 296 | + /** |
| 297 | + * We don't need to remap global ords iff this aggregator: |
| 298 | + * - is not a child of a bucket aggregator AND |
| 299 | + * - has no include/exclude rules AND |
| 300 | + * - has no sub-aggregator |
| 301 | + **/ |
| 302 | + remapGlobalOrd = false; |
| 303 | + } |
294 | 304 | return new GlobalOrdinalsSignificantTermsAggregator(name, factories,
|
295 | 305 | (ValuesSource.Bytes.WithOrdinals.FieldData) valuesSource, format, bucketCountThresholds, filter,
|
296 |
| - aggregationContext, parent, false, significanceHeuristic, termsAggregatorFactory, pipelineAggregators, metaData); |
297 |
| - |
298 |
| - } |
299 |
| - |
300 |
| - }, |
301 |
| - GLOBAL_ORDINALS_HASH(new ParseField("global_ordinals_hash")) { |
302 |
| - |
303 |
| - @Override |
304 |
| - Aggregator create(String name, |
305 |
| - AggregatorFactories factories, |
306 |
| - ValuesSource valuesSource, |
307 |
| - DocValueFormat format, |
308 |
| - TermsAggregator.BucketCountThresholds bucketCountThresholds, |
309 |
| - IncludeExclude includeExclude, |
310 |
| - SearchContext aggregationContext, |
311 |
| - Aggregator parent, |
312 |
| - SignificanceHeuristic significanceHeuristic, |
313 |
| - SignificantTermsAggregatorFactory termsAggregatorFactory, |
314 |
| - List<PipelineAggregator> pipelineAggregators, |
315 |
| - Map<String, Object> metaData) throws IOException { |
316 |
| - |
317 |
| - final IncludeExclude.OrdinalsFilter filter = includeExclude == null ? null : includeExclude.convertToOrdinalsFilter(format); |
318 |
| - return new GlobalOrdinalsSignificantTermsAggregator(name, factories, |
319 |
| - (ValuesSource.Bytes.WithOrdinals.FieldData) valuesSource, format, bucketCountThresholds, filter, aggregationContext, parent, |
320 |
| - true, significanceHeuristic, termsAggregatorFactory, pipelineAggregators, metaData); |
| 306 | + aggregationContext, parent, remapGlobalOrd, significanceHeuristic, termsAggregatorFactory, pipelineAggregators, metaData); |
321 | 307 |
|
322 | 308 | }
|
323 | 309 | };
|
324 | 310 |
|
325 |
| - public static ExecutionMode fromString(String value) { |
326 |
| - for (ExecutionMode mode : values()) { |
327 |
| - if (mode.parseField.match(value)) { |
328 |
| - return mode; |
329 |
| - } |
| 311 | + public static ExecutionMode fromString(String value, final DeprecationLogger deprecationLogger) { |
| 312 | + if ("global_ordinals".equals(value)) { |
| 313 | + return GLOBAL_ORDINALS; |
| 314 | + } else if ("global_ordinals_hash".equals(value)) { |
| 315 | + deprecationLogger.deprecated("global_ordinals_hash is deprecated. Please use [global_ordinals] instead."); |
| 316 | + return GLOBAL_ORDINALS; |
| 317 | + } else if ("map".equals(value)) { |
| 318 | + return MAP; |
330 | 319 | }
|
331 |
| - throw new IllegalArgumentException("Unknown `execution_hint`: [" + value + "], expected any of " + Arrays.toString(values())); |
| 320 | + throw new IllegalArgumentException("Unknown `execution_hint`: [" + value + "], expected any of [map, global_ordinals]"); |
332 | 321 | }
|
333 | 322 |
|
334 | 323 | private final ParseField parseField;
|
|
0 commit comments