Commit 671f01b
authored
* Fix geo_centroid over geo_shape merging multiple shards (#144637) (#144755)
As described in #144504 we are seeing different results between `geo_centroid` in QueryDSL and ES|QL's `ST_CENTROID_AGG` when the data is `geo_shape` (or cartesian shapes). The root cause turned out to be that `geo_centriod` was using point-only logic for merging intermediate aggregation results between shards, which means it was considering doc-count only for the weighted merge, and missing:
* Area weights (large polygons count more than small ones, and long lines count more than short ones)
* Dimensional type (shards with only points should not count at all if other shards contain lines or polygons)
This PR contains appropriate unit tests, but manual testing on the OSM dataset we used in the benchmarking leads to:
| test | ESQL doc count | ESQL centroid | Query DSL doc count| QueryDSL centroid |
| --- | --- | --- | --- | --- |
| original | 3818897 | POINT (0.7135620032440881 54.048676344286505) | 3818897 | {lat: 52.91002138728532, lon: 4.350566187678227} |
| after area-weight fix | 3818897 | POINT (0.7135620032440897 54.04867634428662) | 3818897 | {lat: 51.63239198052063, lon: 8.3761283280999} |
| after dimensional-type fix | 3818897 | POINT (0.7135620032440892 54.04867634428658) | 2017758 | {lat: 54.048676344287394, lon: 0.7135620032440999 } |
Note: the small deviations on the 15th and 16th decimal point of the ES|QL results actually occur when simply re-running the same query over and over and are likely a result of floating point errors related to the order in which results are added to the [Kahan summation](https://en.wikipedia.org/wiki/Kahan_summation_algorithm) and are not related to the fixes.
* Make cartesian and geo centroids more similar for easier review
1 parent 4c74987 commit 671f01b
File tree
13 files changed
+355
-29
lines changed- docs/changelog
- server/src/main
- java/org/elasticsearch/search/aggregations/metrics
- resources/transport
- definitions/referable
- upper_bounds
- x-pack/plugin/spatial/src
- main/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics
- test/java/org/elasticsearch/xpack/spatial/search/aggregations/metrics
13 files changed
+355
-29
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 99 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
31 | 43 | | |
32 | 44 | | |
| 45 | + | |
33 | 46 | | |
34 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
35 | 52 | | |
36 | 53 | | |
37 | 54 | | |
38 | 55 | | |
39 | 56 | | |
| 57 | + | |
40 | 58 | | |
41 | 59 | | |
42 | 60 | | |
| |||
55 | 73 | | |
56 | 74 | | |
57 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
58 | 90 | | |
59 | 91 | | |
60 | 92 | | |
| |||
66 | 98 | | |
67 | 99 | | |
68 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
69 | 112 | | |
70 | 113 | | |
71 | 114 | | |
| |||
80 | 123 | | |
81 | 124 | | |
82 | 125 | | |
83 | | - | |
| 126 | + | |
84 | 127 | | |
85 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
86 | 132 | | |
87 | 133 | | |
88 | 134 | | |
| 135 | + | |
89 | 136 | | |
90 | 137 | | |
91 | 138 | | |
92 | 139 | | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
93 | 148 | | |
94 | 149 | | |
95 | 150 | | |
96 | 151 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
104 | 189 | | |
105 | 190 | | |
106 | 191 | | |
107 | 192 | | |
108 | 193 | | |
109 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
110 | 201 | | |
111 | 202 | | |
112 | 203 | | |
| |||
Lines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
31 | 38 | | |
32 | 39 | | |
33 | 40 | | |
| |||
75 | 82 | | |
76 | 83 | | |
77 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
78 | 93 | | |
79 | 94 | | |
80 | 95 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
Lines changed: 9 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
| |||
126 | 125 | | |
127 | 126 | | |
128 | 127 | | |
129 | | - | |
| 128 | + | |
| 129 | + | |
130 | 130 | | |
131 | | - | |
132 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
133 | 135 | | |
134 | | - | |
| 136 | + | |
| 137 | + | |
135 | 138 | | |
136 | 139 | | |
137 | 140 | | |
138 | 141 | | |
139 | | - | |
| 142 | + | |
140 | 143 | | |
141 | 144 | | |
142 | 145 | | |
| |||
Lines changed: 7 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
| 130 | + | |
130 | 131 | | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
135 | 137 | | |
136 | 138 | | |
137 | 139 | | |
| |||
0 commit comments