diff --git a/src/plugins/data/common/search/search_source/fetch/get_search_params.test.ts b/src/plugins/data/common/search/search_source/fetch/get_search_params.test.ts index 1a517bf64d13b..975ad8d4a4878 100644 --- a/src/plugins/data/common/search/search_source/fetch/get_search_params.test.ts +++ b/src/plugins/data/common/search/search_source/fetch/get_search_params.test.ts @@ -9,6 +9,7 @@ import { UI_SETTINGS } from '../../../constants'; import { GetConfigFn } from '../../../types'; import { getSearchParams, getSearchParamsFromRequest } from './get_search_params'; +import { createStubDataView } from '@kbn/data-views-plugin/common/data_views/data_view.stub'; function getConfigStub(config: any = {}): GetConfigFn { return (key) => config[key]; @@ -46,4 +47,50 @@ describe('getSearchParams', () => { query: 123, }); }); + + test('sets expand_wildcards=all if data view has allowHidden=true', () => { + const getConfig = getConfigStub({ + [UI_SETTINGS.COURIER_SET_REQUEST_PREFERENCE]: 'custom', + [UI_SETTINGS.COURIER_CUSTOM_REQUEST_PREFERENCE]: 'aaa', + }); + const index = createStubDataView({ + spec: { + allowHidden: true, + }, + }); + const searchParams = getSearchParamsFromRequest( + { + index, + body: { + query: 123, + track_total_hits: true, + }, + }, + { getConfig } + ); + expect(searchParams).toHaveProperty('expand_wildcards', 'all'); + }); + + test('does not set expand_wildcards if data view has allowHidden=false', () => { + const getConfig = getConfigStub({ + [UI_SETTINGS.COURIER_SET_REQUEST_PREFERENCE]: 'custom', + [UI_SETTINGS.COURIER_CUSTOM_REQUEST_PREFERENCE]: 'aaa', + }); + const index = createStubDataView({ + spec: { + allowHidden: false, + }, + }); + const searchParams = getSearchParamsFromRequest( + { + index, + body: { + query: 123, + track_total_hits: true, + }, + }, + { getConfig } + ); + expect(searchParams).not.toHaveProperty('expand_wildcards', 'all'); + }); }); diff --git a/src/plugins/data/common/search/search_source/fetch/get_search_params.ts b/src/plugins/data/common/search/search_source/fetch/get_search_params.ts index 5f8ca973b3dfe..db630c85177e3 100644 --- a/src/plugins/data/common/search/search_source/fetch/get_search_params.ts +++ b/src/plugins/data/common/search/search_source/fetch/get_search_params.ts @@ -42,8 +42,8 @@ export function getSearchParamsFromRequest( return { index: searchRequest.index.title || searchRequest.index, body, - // @ts-expect-error `track_total_hits` not allowed at top level for `typesWithBodyKey` track_total_hits, + ...(searchRequest.index?.allowHidden && { expand_wildcards: 'all' }), ...searchParams, }; } diff --git a/src/plugins/data_view_editor/public/components/advanced_params_content/advanced_params_content.tsx b/src/plugins/data_view_editor/public/components/advanced_params_content/advanced_params_content.tsx index dcb8e2c1e1d80..db3746d02dc66 100644 --- a/src/plugins/data_view_editor/public/components/advanced_params_content/advanced_params_content.tsx +++ b/src/plugins/data_view_editor/public/components/advanced_params_content/advanced_params_content.tsx @@ -30,14 +30,16 @@ interface AdvancedParamsContentProps { disableAllowHidden: boolean; disableId: boolean; onAllowHiddenChange?: (value: boolean) => void; + defaultVisible?: boolean; } export const AdvancedParamsContent = ({ disableAllowHidden, disableId, onAllowHiddenChange, + defaultVisible = false, }: AdvancedParamsContentProps) => ( - + diff --git a/src/plugins/data_view_editor/public/components/advanced_params_content/advanced_params_section.tsx b/src/plugins/data_view_editor/public/components/advanced_params_content/advanced_params_section.tsx index b313fddb8ee2d..ce52223413ecd 100644 --- a/src/plugins/data_view_editor/public/components/advanced_params_content/advanced_params_section.tsx +++ b/src/plugins/data_view_editor/public/components/advanced_params_content/advanced_params_section.tsx @@ -13,10 +13,11 @@ import { EuiButtonEmpty, EuiSpacer } from '@elastic/eui'; interface Props { children: React.ReactNode; + defaultVisible: boolean; } -export const AdvancedParamsSection = ({ children }: Props) => { - const [isVisible, setIsVisible] = useState(false); +export const AdvancedParamsSection = ({ children, defaultVisible = false }: Props) => { + const [isVisible, setIsVisible] = useState(defaultVisible); const toggleIsVisible = useCallback(() => { setIsVisible(!isVisible); diff --git a/src/plugins/data_view_editor/public/components/data_view_editor_flyout_content.tsx b/src/plugins/data_view_editor/public/components/data_view_editor_flyout_content.tsx index ad344d482c0cf..73432737f9321 100644 --- a/src/plugins/data_view_editor/public/components/data_view_editor_flyout_content.tsx +++ b/src/plugins/data_view_editor/public/components/data_view_editor_flyout_content.tsx @@ -105,6 +105,7 @@ const IndexPatternEditorFlyoutContentComponent = ({ title: editData.getIndexPattern(), id: editData.id, name: editData.name, + allowHidden: editData.getAllowHidden(), ...(editData.timeFieldName ? { timestampField: { label: editData.timeFieldName, value: editData.timeFieldName }, @@ -124,6 +125,7 @@ const IndexPatternEditorFlyoutContentComponent = ({ timeFieldName: formData.timestampField?.value, id: formData.id, name: formData.name, + allowHidden: formData.allowHidden, }; if (type === INDEX_PATTERN_TYPE.ROLLUP && rollupIndex) { @@ -293,6 +295,7 @@ const IndexPatternEditorFlyoutContentComponent = ({ onAllowHiddenChange={() => { form.getFields().title.validate(); }} + defaultVisible={editData?.getAllowHidden()} />