|
51 | 51 | import java.util.Collections; |
52 | 52 | import java.util.List; |
53 | 53 | import java.util.Map; |
| 54 | +import org.apache.logging.log4j.LogManager; |
| 55 | +import org.apache.logging.log4j.Logger; |
| 56 | + |
54 | 57 |
|
55 | 58 | /** |
56 | 59 | * Aggregates data expressed as longs (for efficiency's sake) but formats results as aggregation-specific strings. |
57 | 60 | * |
58 | 61 | * @opensearch.api |
59 | 62 | */ |
| 63 | + |
60 | 64 | public abstract class GeoGridAggregator<T extends BaseGeoGrid> extends BucketsAggregator { |
| 65 | + private static final Logger logger = LogManager.getLogger(GeoGridAggregator.class); |
61 | 66 |
|
62 | 67 | protected final int requiredSize; |
63 | 68 | protected final int shardSize; |
@@ -94,13 +99,21 @@ public ScoreMode scoreMode() { |
94 | 99 | public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, final LeafBucketCollector sub) throws IOException { |
95 | 100 | SortedNumericDocValues values = valuesSource.longValues(ctx); |
96 | 101 | return new LeafBucketCollectorBase(sub, null) { |
| 102 | + final int MAX_TILES_PER_DOCUMENT = 10000; |
| 103 | + |
97 | 104 | @Override |
98 | 105 | public void collect(int doc, long owningBucketOrd) throws IOException { |
99 | 106 | if (values.advanceExact(doc)) { |
100 | 107 | final int valuesCount = values.docValueCount(); |
101 | 108 |
|
| 109 | + if (valuesCount > MAX_TILES_PER_DOCUMENT) { |
| 110 | + // Log a warning so the user knows why data is missing |
| 111 | + logger.warn("Skipping doc [{}] in aggregation [{}] due to excessive tiles: [{}]", doc, name, valuesCount); |
| 112 | + return; |
| 113 | + } |
102 | 114 | long previous = Long.MAX_VALUE; |
103 | 115 | for (int i = 0; i < valuesCount; ++i) { |
| 116 | + |
104 | 117 | final long val = values.nextValue(); |
105 | 118 | if (previous != val || i == 0) { |
106 | 119 | long bucketOrdinal = bucketOrds.add(owningBucketOrd, val); |
|
0 commit comments