Commit 4504cd1
[maps] fix When courier:ignoreFilterIfFieldNotInIndex enabled, geographic filters no longer working (#153816)
Fixes #153595
### Background
When advanced setting `courier:ignoreFilterIfFieldNotInIndex` is
enabled, filters are ignored when data view does not contain the
filtering field. The logic on how this works is captured below for
context.
https://github.com/elastic/kibana/blob/main/packages/kbn-es-query/src/es_query/from_filters.ts#L83
```
.filter((filter) => {
const indexPattern = findIndexPattern(inputDataViews, filter.meta?.index);
return !ignoreFilterIfFieldNotInIndex || filterMatchesIndex(filter, indexPattern);
})
```
https://github.com/elastic/kibana/blob/main/packages/kbn-es-query/src/es_query/filter_matches_index.ts#L20
```
export function filterMatchesIndex(filter: Filter, indexPattern?: DataViewBase | null) {
if (!filter.meta?.key || !indexPattern) {
return true;
}
// Fixes #89878
// Custom filters may refer multiple fields. Validate the index id only.
if (filter.meta?.type === 'custom') {
return filter.meta.index === indexPattern.id;
}
return indexPattern.fields.some((field) => field.name === filter.meta.key);
}
```
The problem is that
[mapSpatialFilter](https://github.com/elastic/kibana/blob/8.7/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts#L12)
is setting `meta.key` property. This causes `filterMatchesIndex` check
to fail for spatial filters.
Spatial filters are designed to work across data views and avoid the
problems that `courier:ignoreFilterIfFieldNotInIndex` solves. As such,
spatial filters should not set `meta.key` property and not get removed
when `courier:ignoreFilterIfFieldNotInIndex` is enabled.
### Test
* set advanced setting `courier:ignoreFilterIfFieldNotInIndex` and
refresh browser
* install 2 or more sample data sets
* create a new map
* add documents layer from one sample data set
* add documents layer from another sample data set
* create spatial filter on map,
https://www.elastic.co/guide/en/kibana/8.6/maps-create-filter-from-map.html#maps-spatial-filters
* Verify filter is applied to both layers
---------
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>1 parent b692e34 commit 4504cd1
File tree
6 files changed
+114
-144
lines changed- src/plugins/data/public/query/filter_manager/lib/mappers
- x-pack/plugins/maps
- common/elasticsearch_util
- public
- classes/sources/es_geo_grid_source
- routes/map_page/map_app
6 files changed
+114
-144
lines changedLines changed: 22 additions & 94 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | | - | |
13 | | - | |
| 13 | + | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | 17 | | |
45 | 18 | | |
46 | | - | |
47 | | - | |
48 | | - | |
| 19 | + | |
49 | 20 | | |
50 | 21 | | |
51 | 22 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | 23 | | |
| 24 | + | |
| 25 | + | |
110 | 26 | | |
111 | 27 | | |
112 | 28 | | |
113 | 29 | | |
114 | 30 | | |
115 | 31 | | |
116 | | - | |
| 32 | + | |
117 | 33 | | |
118 | | - | |
119 | | - | |
120 | | - | |
| 34 | + | |
121 | 35 | | |
122 | 36 | | |
123 | 37 | | |
| |||
127 | 41 | | |
128 | 42 | | |
129 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
Lines changed: 7 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
| 13 | + | |
19 | 14 | | |
20 | | - | |
21 | 15 | | |
22 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | 25 | | |
39 | 26 | | |
Lines changed: 66 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
19 | 46 | | |
20 | 47 | | |
21 | 48 | | |
| |||
28 | 55 | | |
29 | 56 | | |
30 | 57 | | |
31 | | - | |
| 58 | + | |
32 | 59 | | |
33 | 60 | | |
34 | 61 | | |
| |||
65 | 92 | | |
66 | 93 | | |
67 | 94 | | |
68 | | - | |
| 95 | + | |
69 | 96 | | |
70 | 97 | | |
71 | 98 | | |
| |||
102 | 129 | | |
103 | 130 | | |
104 | 131 | | |
105 | | - | |
| 132 | + | |
106 | 133 | | |
107 | 134 | | |
108 | 135 | | |
| |||
139 | 166 | | |
140 | 167 | | |
141 | 168 | | |
142 | | - | |
| 169 | + | |
143 | 170 | | |
144 | 171 | | |
145 | 172 | | |
| |||
176 | 203 | | |
177 | 204 | | |
178 | 205 | | |
179 | | - | |
| 206 | + | |
180 | 207 | | |
181 | 208 | | |
182 | 209 | | |
| |||
276 | 303 | | |
277 | 304 | | |
278 | 305 | | |
279 | | - | |
| 306 | + | |
280 | 307 | | |
281 | 308 | | |
282 | 309 | | |
| |||
312 | 339 | | |
313 | 340 | | |
314 | 341 | | |
315 | | - | |
316 | 342 | | |
317 | 343 | | |
318 | 344 | | |
| |||
384 | 410 | | |
385 | 411 | | |
386 | 412 | | |
387 | | - | |
| 413 | + | |
388 | 414 | | |
389 | 415 | | |
390 | 416 | | |
| |||
444 | 470 | | |
445 | 471 | | |
446 | 472 | | |
447 | | - | |
448 | 473 | | |
449 | 474 | | |
450 | 475 | | |
| |||
531 | 556 | | |
532 | 557 | | |
533 | 558 | | |
534 | | - | |
| 559 | + | |
535 | 560 | | |
536 | 561 | | |
537 | 562 | | |
| |||
566 | 591 | | |
567 | 592 | | |
568 | 593 | | |
569 | | - | |
570 | 594 | | |
571 | 595 | | |
572 | 596 | | |
| |||
637 | 661 | | |
638 | 662 | | |
639 | 663 | | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
640 | 695 | | |
641 | 696 | | |
642 | 697 | | |
| |||
0 commit comments