-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[maps] fix When courier:ignoreFilterIfFieldNotInIndex enabled, geographic filters no longer working #153816
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
Conversation
…phic filters no longer working
| } | ||
|
|
||
| // ignore results for outdated requests | ||
| if (!_.isEqual(nextIndexPatternIds, this._prevIndexPatternIds)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an unrelated fix for an issue where timing of getIndexPatterns response are out of order, resulting in setting state to a stale value.
|
@elasticmachine merge upstream |
|
@elasticmachine merge upstream |
|
Pinging @elastic/kibana-presentation (Team:Presentation) |
nickpeihl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! code review and tested with and without courier:ignoreFilterIfFieldNotInIndex enabled.
It is not possible to specify a data view using the Edit filter option in the filter pill context menu, however this is an issue in main and not related to this PR.
|
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Async chunks
Page load bundle
Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
stratoula
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes LGTM!
…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)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation and see the Github Action logs for details |
…geographic filters no longer working (#153816) (#154162) # Backport This will backport the following commits from `main` to `8.7`: - [[maps] fix When courier:ignoreFilterIfFieldNotInIndex enabled, geographic filters no longer working (#153816)](#153816) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Nathan Reese","email":"reese.nathan@elastic.co"},"sourceCommit":{"committedDate":"2023-03-31T13:59:01Z","message":"[maps] fix When courier:ignoreFilterIfFieldNotInIndex enabled, geographic filters no longer working (#153816)\n\nFixes https://github.com/elastic/kibana/issues/153595\r\n\r\n### Background\r\n\r\nWhen advanced setting `courier:ignoreFilterIfFieldNotInIndex` is\r\nenabled, filters are ignored when data view does not contain the\r\nfiltering field. The logic on how this works is captured below for\r\ncontext.\r\n\r\n\r\nhttps://github.com/elastic/kibana/blob/main/packages/kbn-es-query/src/es_query/from_filters.ts#L83\r\n```\r\n .filter((filter) => {\r\n const indexPattern = findIndexPattern(inputDataViews, filter.meta?.index);\r\n return !ignoreFilterIfFieldNotInIndex || filterMatchesIndex(filter, indexPattern);\r\n })\r\n```\r\n\r\n\r\nhttps://github.com/elastic/kibana/blob/main/packages/kbn-es-query/src/es_query/filter_matches_index.ts#L20\r\n```\r\nexport function filterMatchesIndex(filter: Filter, indexPattern?: DataViewBase | null) {\r\n if (!filter.meta?.key || !indexPattern) {\r\n return true;\r\n }\r\n\r\n // Fixes https://github.com/elastic/kibana/issues/89878\r\n // Custom filters may refer multiple fields. Validate the index id only.\r\n if (filter.meta?.type === 'custom') {\r\n return filter.meta.index === indexPattern.id;\r\n }\r\n\r\n return indexPattern.fields.some((field) => field.name === filter.meta.key);\r\n}\r\n```\r\n\r\nThe problem is that\r\n[mapSpatialFilter](https://github.com/elastic/kibana/blob/8.7/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts#L12)\r\nis setting `meta.key` property. This causes `filterMatchesIndex` check\r\nto fail for spatial filters.\r\n\r\nSpatial filters are designed to work across data views and avoid the\r\nproblems that `courier:ignoreFilterIfFieldNotInIndex` solves. As such,\r\nspatial filters should not set `meta.key` property and not get removed\r\nwhen `courier:ignoreFilterIfFieldNotInIndex` is enabled.\r\n\r\n### Test\r\n* set advanced setting `courier:ignoreFilterIfFieldNotInIndex` and\r\nrefresh browser\r\n* install 2 or more sample data sets\r\n* create a new map\r\n* add documents layer from one sample data set\r\n* add documents layer from another sample data set\r\n* create spatial filter on map,\r\nhttps://www.elastic.co/guide/en/kibana/8.6/maps-create-filter-from-map.html#maps-spatial-filters\r\n* Verify filter is applied to both layers\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"4504cd18c07c0f0af94830558f7906dd77a2b217","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Presentation","auto-backport","Feature:Maps","v8.8.0","v8.7.1"],"number":153816,"url":"https://github.com/elastic/kibana/pull/153816","mergeCommit":{"message":"[maps] fix When courier:ignoreFilterIfFieldNotInIndex enabled, geographic filters no longer working (#153816)\n\nFixes https://github.com/elastic/kibana/issues/153595\r\n\r\n### Background\r\n\r\nWhen advanced setting `courier:ignoreFilterIfFieldNotInIndex` is\r\nenabled, filters are ignored when data view does not contain the\r\nfiltering field. The logic on how this works is captured below for\r\ncontext.\r\n\r\n\r\nhttps://github.com/elastic/kibana/blob/main/packages/kbn-es-query/src/es_query/from_filters.ts#L83\r\n```\r\n .filter((filter) => {\r\n const indexPattern = findIndexPattern(inputDataViews, filter.meta?.index);\r\n return !ignoreFilterIfFieldNotInIndex || filterMatchesIndex(filter, indexPattern);\r\n })\r\n```\r\n\r\n\r\nhttps://github.com/elastic/kibana/blob/main/packages/kbn-es-query/src/es_query/filter_matches_index.ts#L20\r\n```\r\nexport function filterMatchesIndex(filter: Filter, indexPattern?: DataViewBase | null) {\r\n if (!filter.meta?.key || !indexPattern) {\r\n return true;\r\n }\r\n\r\n // Fixes https://github.com/elastic/kibana/issues/89878\r\n // Custom filters may refer multiple fields. Validate the index id only.\r\n if (filter.meta?.type === 'custom') {\r\n return filter.meta.index === indexPattern.id;\r\n }\r\n\r\n return indexPattern.fields.some((field) => field.name === filter.meta.key);\r\n}\r\n```\r\n\r\nThe problem is that\r\n[mapSpatialFilter](https://github.com/elastic/kibana/blob/8.7/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts#L12)\r\nis setting `meta.key` property. This causes `filterMatchesIndex` check\r\nto fail for spatial filters.\r\n\r\nSpatial filters are designed to work across data views and avoid the\r\nproblems that `courier:ignoreFilterIfFieldNotInIndex` solves. As such,\r\nspatial filters should not set `meta.key` property and not get removed\r\nwhen `courier:ignoreFilterIfFieldNotInIndex` is enabled.\r\n\r\n### Test\r\n* set advanced setting `courier:ignoreFilterIfFieldNotInIndex` and\r\nrefresh browser\r\n* install 2 or more sample data sets\r\n* create a new map\r\n* add documents layer from one sample data set\r\n* add documents layer from another sample data set\r\n* create spatial filter on map,\r\nhttps://www.elastic.co/guide/en/kibana/8.6/maps-create-filter-from-map.html#maps-spatial-filters\r\n* Verify filter is applied to both layers\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"4504cd18c07c0f0af94830558f7906dd77a2b217"}},"sourceBranch":"main","suggestedTargetBranches":["8.7"],"targetPullRequestStates":[{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/153816","number":153816,"mergeCommit":{"message":"[maps] fix When courier:ignoreFilterIfFieldNotInIndex enabled, geographic filters no longer working (#153816)\n\nFixes https://github.com/elastic/kibana/issues/153595\r\n\r\n### Background\r\n\r\nWhen advanced setting `courier:ignoreFilterIfFieldNotInIndex` is\r\nenabled, filters are ignored when data view does not contain the\r\nfiltering field. The logic on how this works is captured below for\r\ncontext.\r\n\r\n\r\nhttps://github.com/elastic/kibana/blob/main/packages/kbn-es-query/src/es_query/from_filters.ts#L83\r\n```\r\n .filter((filter) => {\r\n const indexPattern = findIndexPattern(inputDataViews, filter.meta?.index);\r\n return !ignoreFilterIfFieldNotInIndex || filterMatchesIndex(filter, indexPattern);\r\n })\r\n```\r\n\r\n\r\nhttps://github.com/elastic/kibana/blob/main/packages/kbn-es-query/src/es_query/filter_matches_index.ts#L20\r\n```\r\nexport function filterMatchesIndex(filter: Filter, indexPattern?: DataViewBase | null) {\r\n if (!filter.meta?.key || !indexPattern) {\r\n return true;\r\n }\r\n\r\n // Fixes https://github.com/elastic/kibana/issues/89878\r\n // Custom filters may refer multiple fields. Validate the index id only.\r\n if (filter.meta?.type === 'custom') {\r\n return filter.meta.index === indexPattern.id;\r\n }\r\n\r\n return indexPattern.fields.some((field) => field.name === filter.meta.key);\r\n}\r\n```\r\n\r\nThe problem is that\r\n[mapSpatialFilter](https://github.com/elastic/kibana/blob/8.7/src/plugins/data/public/query/filter_manager/lib/mappers/map_spatial_filter.ts#L12)\r\nis setting `meta.key` property. This causes `filterMatchesIndex` check\r\nto fail for spatial filters.\r\n\r\nSpatial filters are designed to work across data views and avoid the\r\nproblems that `courier:ignoreFilterIfFieldNotInIndex` solves. As such,\r\nspatial filters should not set `meta.key` property and not get removed\r\nwhen `courier:ignoreFilterIfFieldNotInIndex` is enabled.\r\n\r\n### Test\r\n* set advanced setting `courier:ignoreFilterIfFieldNotInIndex` and\r\nrefresh browser\r\n* install 2 or more sample data sets\r\n* create a new map\r\n* add documents layer from one sample data set\r\n* add documents layer from another sample data set\r\n* create spatial filter on map,\r\nhttps://www.elastic.co/guide/en/kibana/8.6/maps-create-filter-from-map.html#maps-spatial-filters\r\n* Verify filter is applied to both layers\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"4504cd18c07c0f0af94830558f7906dd77a2b217"}},{"branch":"8.7","label":"v8.7.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Nathan Reese <reese.nathan@elastic.co>
…filter disappear from map (#154087) Fixes #107044 and #109340 ### Background In Maps, users can [create spatial filters](https://www.elastic.co/guide/en/kibana/current/maps-create-filter-from-map.html). The filter is added to the Filter bar. <img width="300" alt="Screen Shot 2021-09-03 at 4 07 33 PM" src="https://user-images.githubusercontent.com/373691/133142628-9b03dec2-69ee-4c7c-ac8d-841168c88a94.png"> There are 2 important properties about spatial filters created from a Map: * `filter.meta.type` is set to `spatial_filter`. Maps uses `filter.meta.type` to identify spatial filters. Spatial filters are displayed on the map to provide a visual reference of all applied spatial filters. * `filter.meta.isMultiIndex` is set to true since Elasticsearch Query DSL for the filter is not tied to a single index pattern or field. The Elasticsearch Query DSL is generated in such a way that the filter works for all map layers, regardless of index pattern or spatial field. In the screenshot above a single filter is filtering both layers, even though they are from different index patterns and different spatial fields. * Each layer identifies one or more geo_point or geo_shape fields that is used to display features for that layer * The Elasticsearch Query DSL combines these into a `bool.should` clause where each field provides a `bool.must` clause ensuring the spatial field exists and that the document satisfies the spatial filter. Any document matching any of the `bool.must` clauses allows the bool.should clause to produce a match. ### Solution [Earlier solution](#111897) proposed Sept 2021. This original effort was abandoned as priorities shifted. I investigated re-opening original solution, which included a filter operator registry. This solution is no longer appropriate with `combined` filters. Instead, this PR takes a less complex approach and when `filter.meta.isMultiIndex`, the filter editor displays the following: * Only displays "custom" editor. "Values" editor is not available * "Edit as filter values" toggle button is not visible * Data view select is not visible * onSubmit does not change filter to "custom" unless DSL is edited <img width="500" alt="Screen Shot 2023-03-30 at 10 33 58 AM" src="https://user-images.githubusercontent.com/373691/228918145-61ddda8b-43a3-44e8-8316-a803473f5a36.png"> ### Test instructions * Install web logs sample data set and open "[Logs] Total Requests and Bytes" map * Click wrench and select "Draw bounds to filter data". Draw bounds and create a filter. * In the Filter bar, Click "Edit filter". * Change the label and click save. The filter should still be displayed on the map and the filter pill should have a new label. <strike>Note for testing, until #153816 is merged, spatial filters with a single geofield will not set `isMultiIndex` to true and will still have the errors referenced in the issues. Once #153816 is merged all spatial filters will set isMultiIndex.</strike> --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Fixes #153595
Background
When advanced setting
courier:ignoreFilterIfFieldNotInIndexis 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
https://github.com/elastic/kibana/blob/main/packages/kbn-es-query/src/es_query/filter_matches_index.ts#L20
The problem is that mapSpatialFilter is setting
meta.keyproperty. This causesfilterMatchesIndexcheck to fail for spatial filters.Spatial filters are designed to work across data views and avoid the problems that
courier:ignoreFilterIfFieldNotInIndexsolves. As such, spatial filters should not setmeta.keyproperty and not get removed whencourier:ignoreFilterIfFieldNotInIndexis enabled.Test
courier:ignoreFilterIfFieldNotInIndexand refresh browser