Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.7] [maps] fix When courier:ignoreFilterIfFieldNotInIndex enabled, geographic filters no longer working (#153816) #154162

Merged
merged 1 commit into from
Mar 31, 2023

Conversation

kibanamachine
Copy link
Contributor

Backport

This will backport the following commits from main to 8.7:

Questions ?

Please refer to the Backport tool documentation

…phic 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>
(cherry picked from commit 4504cd1)
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
maps 2.7MB 2.7MB -213.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
data 407.4KB 407.3KB -192.0B

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @nreese

@kibanamachine kibanamachine deleted the backport/8.7/pr-153816 branch March 31, 2023 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants