diff --git a/src/plugins/data/public/query/query_string/query_string_manager.ts b/src/plugins/data/public/query/query_string/query_string_manager.ts index 754b444435c0..30e8afe6098c 100644 --- a/src/plugins/data/public/query/query_string/query_string_manager.ts +++ b/src/plugins/data/public/query/query_string/query_string_manager.ts @@ -60,14 +60,32 @@ export class QueryStringManager { } public getDefaultQuery() { - return { - query: this.getDefaultQueryString(), - language: this.getDefaultLanguage(), - ...(this.uiSettings && - this.uiSettings.get(UI_SETTINGS.QUERY_ENHANCEMENTS_ENABLED) && { - dataset: this.datasetService?.getDefault(), - }), + const defaultLanguageId = this.getDefaultLanguage(); + const defaultQuery = this.getDefaultQueryString(); + const defaultDataset = this.datasetService?.getDefault(); + + const query = { + query: defaultQuery, + language: defaultLanguageId, + dataset: defaultDataset, }; + + if ( + this.uiSettings && + this.uiSettings.get(UI_SETTINGS.QUERY_ENHANCEMENTS_ENABLED) && + defaultDataset && + this.languageService + ) { + const language = this.languageService.getLanguage(defaultLanguageId); + const newQueryString = language?.getQueryString(query) || ''; + + return { + ...query, + query: newQueryString, + }; + } + + return query; } public formatQuery(query: Query | string | undefined): Query {