Skip to content

Commit 3c75bab

Browse files
authored
guard geoline aggregation from parents aggegator that emit empty buckets (elastic#79129) (elastic#79419)
This change prevents an AIOOBE that might happen with the provided bucket to build the aggregation is bigger that the max bucket that contains data.
1 parent 3a73a4f commit 3c75bab

File tree

2 files changed

+136
-2
lines changed

2 files changed

+136
-2
lines changed

x-pack/plugin/spatial/src/main/java/org/elasticsearch/xpack/spatial/search/aggregations/GeoLineAggregator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void collect(int doc, long bucket) throws IOException {
8585

8686
@Override
8787
public InternalAggregation buildAggregation(long bucket) {
88-
if (valuesSources == null) {
88+
if (valuesSources == null || bucket >= counts.size()) {
8989
return buildEmptyAggregation();
9090
}
9191
boolean complete = counts.get(bucket) <= size;
@@ -98,7 +98,7 @@ public InternalAggregation buildAggregation(long bucket) {
9898

9999
@Override
100100
public InternalAggregation buildEmptyAggregation() {
101-
return new InternalGeoLine(name, null, null, metadata(), true, includeSorts, sortOrder, size);
101+
return new InternalGeoLine(name, new long[0], new double[0], metadata(), true, includeSorts, sortOrder, size);
102102
}
103103

104104
@Override

x-pack/plugin/spatial/src/yamlRestTest/resources/rest-api-spec/test/60_geo_line.yml

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,137 @@
4949
- match: { aggregations.trace.geometry.coordinates.1: [4.91235, 52.374081] }
5050
- match: { aggregations.trace.geometry.coordinates.2: [4.914722, 52.371667] }
5151
- is_true: aggregations.trace.properties.complete
52+
53+
---
54+
"Test empty buckets":
55+
- do:
56+
indices.create:
57+
index: test1
58+
body:
59+
mappings:
60+
properties:
61+
location:
62+
type: geo_point
63+
date:
64+
type: date
65+
entity:
66+
type: keyword
67+
68+
- do:
69+
indices.create:
70+
index: test2
71+
body:
72+
mappings:
73+
properties:
74+
location:
75+
type: geo_point
76+
date:
77+
type: date
78+
entity:
79+
type: keyword
80+
81+
- do:
82+
bulk:
83+
refresh: true
84+
body:
85+
- index:
86+
_index: test1
87+
_id: 1
88+
- '{ "date" : "2020-01-01T01:00:00.0Z", "entity" : "e1", "location" : { "lat" : 50.3, "lon" : 0.13 }}'
89+
- index:
90+
_index: test1
91+
_id: 2
92+
- '{ "date" : "2020-01-01T01:00:01.0Z", "entity" : "e1", "location" : { "lat" : 50.4, "lon" : 0.13 } }'
93+
- index:
94+
_index: test1
95+
_id: 3
96+
- '{ "date" : "2020-01-01T01:00:03.0Z", "entity" : "e1", "location" : { "lat" : 50.5, "lon" : 0.13 }}'
97+
- index:
98+
_index: test2
99+
_id: 1
100+
- '{ "date" : "2020-01-02T02:00:01.0Z", "entity" : "e2", "location" : { "lat" : 51.3, "lon" : 0.13 }}'
101+
- index:
102+
_index: test2
103+
_id: 2
104+
- '{ "date" : "2020-01-02T02:00:02.0Z", "entity" : "e2", "location" : { "lat" : 51.4, "lon" : 0.13 }}'
105+
- index:
106+
_index: test2
107+
_id: 3
108+
- '{ "date" : "2020-01-02T02:00:03.0Z", "entity" : "e2", "location" : { "lat" : 51.5, "lon" : 0.13 }}'
109+
110+
- do:
111+
search:
112+
index: test1,test2
113+
body:
114+
size: 6
115+
aggs:
116+
tracks:
117+
filters:
118+
filters:
119+
1:
120+
term:
121+
entity: e3
122+
2:
123+
term:
124+
entity: e4
125+
aggs:
126+
path:
127+
geo_line:
128+
point:
129+
field: location
130+
sort:
131+
field: date
132+
133+
- match: { hits.total.value: 6 }
134+
- match: { aggregations.tracks.buckets.1.doc_count: 0 }
135+
- match: { aggregations.tracks.buckets.1.path.type: "Feature" }
136+
- match: { aggregations.tracks.buckets.1.path.geometry.type: "LineString" }
137+
- length: { aggregations.tracks.buckets.1.path.geometry.coordinates: 0 }
138+
- match: { aggregations.tracks.buckets.1.path.properties.complete: true }
139+
- match: { aggregations.tracks.buckets.2.doc_count: 0 }
140+
- match: { aggregations.tracks.buckets.2.path.type: "Feature" }
141+
- match: { aggregations.tracks.buckets.2.path.geometry.type: "LineString" }
142+
- length: { aggregations.tracks.buckets.2.path.geometry.coordinates: 0 }
143+
- match: { aggregations.tracks.buckets.2.path.properties.complete: true }
144+
145+
146+
- do:
147+
search:
148+
index: test1,test2
149+
body:
150+
size: 6
151+
aggs:
152+
tracks:
153+
filters:
154+
filters:
155+
1:
156+
term:
157+
entity: e1
158+
2:
159+
term:
160+
entity: e2
161+
aggs:
162+
path:
163+
geo_line:
164+
point:
165+
field: location
166+
sort:
167+
field: date
168+
169+
- match: { hits.total.value: 6 }
170+
- match: { aggregations.tracks.buckets.1.doc_count: 3 }
171+
- match: { aggregations.tracks.buckets.1.path.type: "Feature" }
172+
- match: { aggregations.tracks.buckets.1.path.geometry.type: "LineString" }
173+
- length: { aggregations.tracks.buckets.1.path.geometry.coordinates: 3 }
174+
- match: { aggregations.tracks.buckets.1.path.geometry.coordinates.0: [0.13,50.3] }
175+
- match: { aggregations.tracks.buckets.1.path.geometry.coordinates.1: [0.13,50.4] }
176+
- match: { aggregations.tracks.buckets.1.path.geometry.coordinates.2: [0.13,50.5] }
177+
- match: { aggregations.tracks.buckets.1.path.properties.complete: true }
178+
- match: { aggregations.tracks.buckets.2.doc_count: 3 }
179+
- match: { aggregations.tracks.buckets.2.path.type: "Feature" }
180+
- match: { aggregations.tracks.buckets.2.path.geometry.type: "LineString" }
181+
- length: { aggregations.tracks.buckets.2.path.geometry.coordinates: 3 }
182+
- match: { aggregations.tracks.buckets.2.path.geometry.coordinates.0: [0.13,51.3] }
183+
- match: { aggregations.tracks.buckets.2.path.geometry.coordinates.1: [0.13,51.4] }
184+
- match: { aggregations.tracks.buckets.2.path.geometry.coordinates.2: [0.13,51.5] }
185+
- match: { aggregations.tracks.buckets.2.path.properties.complete: true }

0 commit comments

Comments
 (0)