|
20 | 20 | package org.elasticsearch.search.aggregations.bucket.terms;
|
21 | 21 |
|
22 | 22 | import org.apache.logging.log4j.LogManager;
|
23 |
| -import org.apache.lucene.index.LeafReaderContext; |
24 | 23 | import org.apache.lucene.search.IndexSearcher;
|
25 | 24 | import org.elasticsearch.common.ParseField;
|
26 | 25 | import org.elasticsearch.common.logging.DeprecationLogger;
|
@@ -134,7 +133,7 @@ protected Aggregator doCreateInternal(ValuesSource valuesSource, Aggregator pare
|
134 | 133 | if (valuesSource instanceof ValuesSource.Bytes.WithOrdinals == false) {
|
135 | 134 | execution = ExecutionMode.MAP;
|
136 | 135 | }
|
137 |
| - final long maxOrd = getMaxOrd(context.searcher(), valuesSource, execution); |
| 136 | + final long maxOrd = execution == ExecutionMode.GLOBAL_ORDINALS ? getMaxOrd(valuesSource, context.searcher()) : -1; |
138 | 137 | if (execution == null) {
|
139 | 138 | execution = ExecutionMode.GLOBAL_ORDINALS;
|
140 | 139 | }
|
@@ -208,23 +207,13 @@ static SubAggCollectionMode subAggCollectionMode(int expectedSize, long maxOrd)
|
208 | 207 | }
|
209 | 208 |
|
210 | 209 | /**
|
211 |
| - * Get the maximum ordinal value for the provided {@link ValuesSource} or -1 |
| 210 | + * Get the maximum global ordinal value for the provided {@link ValuesSource} or -1 |
212 | 211 | * if the values source is not an instance of {@link ValuesSource.Bytes.WithOrdinals}.
|
213 | 212 | */
|
214 |
| - static long getMaxOrd(IndexSearcher searcher, ValuesSource source, ExecutionMode executionMode) throws IOException { |
| 213 | + static long getMaxOrd(ValuesSource source, IndexSearcher searcher) throws IOException { |
215 | 214 | if (source instanceof ValuesSource.Bytes.WithOrdinals) {
|
216 | 215 | ValuesSource.Bytes.WithOrdinals valueSourceWithOrdinals = (ValuesSource.Bytes.WithOrdinals) source;
|
217 |
| - if (executionMode == ExecutionMode.MAP) { |
218 |
| - // global ordinals are not requested so we don't load them |
219 |
| - // and return the biggest cardinality per segment instead. |
220 |
| - long maxOrd = -1; |
221 |
| - for (LeafReaderContext leaf : searcher.getIndexReader().leaves()) { |
222 |
| - maxOrd = Math.max(maxOrd, valueSourceWithOrdinals.ordinalsValues(leaf).getValueCount()); |
223 |
| - } |
224 |
| - return maxOrd; |
225 |
| - } else { |
226 |
| - return valueSourceWithOrdinals.globalMaxOrd(searcher); |
227 |
| - } |
| 216 | + return valueSourceWithOrdinals.globalMaxOrd(searcher); |
228 | 217 | } else {
|
229 | 218 | return -1;
|
230 | 219 | }
|
@@ -269,7 +258,7 @@ Aggregator create(String name,
|
269 | 258 | List<PipelineAggregator> pipelineAggregators,
|
270 | 259 | Map<String, Object> metaData) throws IOException {
|
271 | 260 |
|
272 |
| - final long maxOrd = getMaxOrd(context.searcher(), valuesSource, ExecutionMode.GLOBAL_ORDINALS); |
| 261 | + final long maxOrd = getMaxOrd(valuesSource, context.searcher()); |
273 | 262 | assert maxOrd != -1;
|
274 | 263 | final double ratio = maxOrd / ((double) context.searcher().getIndexReader().numDocs());
|
275 | 264 |
|
|
0 commit comments