Skip to content

Commit c020ab9

Browse files
[9.2] [Discover][Advanced Settings] Fix missing fields when using combined filters with ignoreFilterIfFieldNotInIndex UI setting (#238945) (#239190)
# Backport This will backport the following commits from `main` to `9.2`: - [[Discover][Advanced Settings] Fix missing fields when using combined filters with `ignoreFilterIfFieldNotInIndex` UI setting (#238945)](#238945) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Miłosz Radzyński","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-10-15T16:22:50Z","message":"[Discover][Advanced Settings] Fix missing fields when using combined filters with `ignoreFilterIfFieldNotInIndex` UI setting (#238945)\n\n## Summary\n\nThis PR ensures that the combined filters will be taken into account\nwhen selecting the correct fields for the query, with the advanced\nsetting: `courier:ignoreFilterIfFieldNotInIndex` enabled.\nCloses: #233042\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n- [ ]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [ ] If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n- [ ] This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.\n- [ ] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [ ] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n- [x] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.","sha":"251535685b558fb52e9a62d9f7fcece79a57a26c","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:DataDiscovery","backport:version","v9.2.0","v9.3.0","v9.1.6","v8.18.9","v8.19.6"],"title":"[Discover][Advanced Settings] Fix missing fields when using combined filters with `ignoreFilterIfFieldNotInIndex` UI setting","number":238945,"url":"https://github.com/elastic/kibana/pull/238945","mergeCommit":{"message":"[Discover][Advanced Settings] Fix missing fields when using combined filters with `ignoreFilterIfFieldNotInIndex` UI setting (#238945)\n\n## Summary\n\nThis PR ensures that the combined filters will be taken into account\nwhen selecting the correct fields for the query, with the advanced\nsetting: `courier:ignoreFilterIfFieldNotInIndex` enabled.\nCloses: #233042\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n- [ ]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [ ] If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n- [ ] This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.\n- [ ] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [ ] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n- [x] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.","sha":"251535685b558fb52e9a62d9f7fcece79a57a26c"}},"sourceBranch":"main","suggestedTargetBranches":["9.2","9.1","8.18","8.19"],"targetPullRequestStates":[{"branch":"9.2","label":"v9.2.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/238945","number":238945,"mergeCommit":{"message":"[Discover][Advanced Settings] Fix missing fields when using combined filters with `ignoreFilterIfFieldNotInIndex` UI setting (#238945)\n\n## Summary\n\nThis PR ensures that the combined filters will be taken into account\nwhen selecting the correct fields for the query, with the advanced\nsetting: `courier:ignoreFilterIfFieldNotInIndex` enabled.\nCloses: #233042\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)\n- [ ]\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [ ] If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\n- [ ] This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.\n- [ ] [Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed\n- [ ] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n- [x] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.","sha":"251535685b558fb52e9a62d9f7fcece79a57a26c"}},{"branch":"9.1","label":"v9.1.6","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.9","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.6","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Miłosz Radzyński <[email protected]>
1 parent d37cb19 commit c020ab9

File tree

2 files changed

+81
-9
lines changed

2 files changed

+81
-9
lines changed

src/platform/plugins/shared/data/common/search/search_source/query_to_fields.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import type { EsQuerySortValue, SearchRequest } from '../..';
1111
import { queryToFields, SortDirection } from '../..';
1212
import type { DataViewLazy } from '@kbn/data-views-plugin/common';
13+
import { type Filter, FILTERS } from '@kbn/es-query';
1314

1415
describe('SearchSource#queryToFields', () => {
1516
it('should include time field', async () => {
@@ -81,4 +82,55 @@ describe('SearchSource#queryToFields', () => {
8182
const { fieldName } = dataView.getFields.mock.calls[0][0];
8283
expect(fieldName).toEqual(['@timestamp']);
8384
});
85+
86+
it('should include fields from nested combined filters', async () => {
87+
const dataView = {
88+
getSourceFiltering: jest.fn().mockReturnValue({ excludes: [] }),
89+
getFields: jest.fn().mockResolvedValue({
90+
getFieldMapSorted: jest.fn(),
91+
}),
92+
};
93+
94+
const combinedFilter: Filter = {
95+
meta: {
96+
type: FILTERS.COMBINED,
97+
disabled: false,
98+
params: [
99+
{
100+
meta: { disabled: false },
101+
query: {
102+
exists: { field: 'process.name' },
103+
},
104+
} as Filter,
105+
{
106+
meta: {
107+
type: FILTERS.COMBINED,
108+
disabled: false,
109+
params: [
110+
{
111+
meta: { key: 'attributes.process.name', disabled: false },
112+
} as Filter,
113+
{
114+
meta: { disabled: false },
115+
query: {
116+
exists: { field: 'stream.name' },
117+
},
118+
} as Filter,
119+
],
120+
},
121+
} as Filter,
122+
],
123+
},
124+
} as Filter;
125+
126+
const request: SearchRequest = {
127+
query: [],
128+
filters: [combinedFilter],
129+
};
130+
131+
await queryToFields({ dataView: dataView as unknown as DataViewLazy, request });
132+
133+
const { fieldName } = dataView.getFields.mock.calls[0][0];
134+
expect(fieldName).toEqual(['process.name', 'attributes.process.name', 'stream.name']);
135+
});
84136
});

src/platform/plugins/shared/data/common/search/search_source/query_to_fields.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,35 @@
88
*/
99

1010
import type { DataViewLazy } from '@kbn/data-views-plugin/common';
11-
import { fromKueryExpression, getKqlFieldNames, isFilter, isOfQueryType } from '@kbn/es-query';
11+
import {
12+
fromKueryExpression,
13+
getFilterField,
14+
getKqlFieldNames,
15+
isCombinedFilter,
16+
isFilter,
17+
isOfQueryType,
18+
type Filter,
19+
} from '@kbn/es-query';
1220
import type { SearchRequest } from './fetch';
1321
import type { EsQuerySortValue } from '../..';
1422

23+
const collectFilterFields = (filter: Filter, acc: string[] = []): string[] => {
24+
if (!isFilter(filter) || filter.meta?.disabled === true) return acc;
25+
26+
if (isCombinedFilter(filter)) {
27+
for (const nested of filter.meta.params ?? []) {
28+
collectFilterFields(nested, acc);
29+
}
30+
31+
return acc;
32+
}
33+
34+
const field = filter.meta?.key ?? getFilterField(filter);
35+
if (field) acc.push(field);
36+
37+
return acc;
38+
};
39+
1540
export async function queryToFields({
1641
dataView,
1742
sort,
@@ -33,15 +58,10 @@ export async function queryToFields({
3358
fields = fields.concat(queryFields);
3459
}
3560
}
61+
3662
const { filters = [] } = request;
37-
for (const f of typeof filters === 'function' ? filters() : filters) {
38-
// unified search bar filters have meta object and key (regular filters)
39-
// unified search bar "custom" filters ("Edit as query DSL", where meta.key is not present but meta is)
40-
// Any other Elasticsearch query DSL filter that gets passed in by consumers (not coming from unified search, and these probably won't have a meta key at all)
41-
if (isFilter(f) && f?.meta?.key && f.meta.disabled !== true) {
42-
fields.push(f.meta.key);
43-
}
44-
}
63+
const requestFilters = typeof filters === 'function' ? filters() : filters;
64+
fields = fields.concat(requestFilters.flatMap((filter) => collectFilterFields(filter)));
4565

4666
// if source filtering is enabled, we need to fetch all the fields
4767
const fieldName =

0 commit comments

Comments
 (0)