diff --git a/x-pack/legacy/plugins/canvas/canvas_plugin_src/functions/server/esdocs.ts b/x-pack/legacy/plugins/canvas/canvas_plugin_src/functions/server/esdocs.ts index fb118c841fffa..3dcc6807724b4 100644 --- a/x-pack/legacy/plugins/canvas/canvas_plugin_src/functions/server/esdocs.ts +++ b/x-pack/legacy/plugins/canvas/canvas_plugin_src/functions/server/esdocs.ts @@ -81,7 +81,7 @@ export function esdocs(): ExpressionFunction<'esdocs', Filter, Arguments, any> { }); if (index) { - query.from(index.toLowerCase()); + query.from(index); } if (fields) { @@ -92,7 +92,7 @@ export function esdocs(): ExpressionFunction<'esdocs', Filter, Arguments, any> { if (sort) { const [sortField, sortOrder] = sort.split(',').map(str => str.trim()); if (sortField) { - query.order(`"${sortField}"`, sortOrder.toLowerCase() === 'asc'); + query.order(`"${sortField}"`, sortOrder === 'asc'); } } diff --git a/x-pack/legacy/plugins/canvas/public/components/es_index_select/es_index_select.js b/x-pack/legacy/plugins/canvas/public/components/es_index_select/es_index_select.js index eff835e84e411..edc4506f20bda 100644 --- a/x-pack/legacy/plugins/canvas/public/components/es_index_select/es_index_select.js +++ b/x-pack/legacy/plugins/canvas/public/components/es_index_select/es_index_select.js @@ -18,7 +18,7 @@ export const ESIndexSelect = ({ value, loading, indices, onChange, onFocus, onBl return ( onChange(get(index, 'label', defaultIndex).toLowerCase())} + onChange={([index]) => onChange(get(index, 'label', defaultIndex))} onSearchChange={searchValue => { // resets input when user starts typing if (searchValue) { diff --git a/x-pack/legacy/plugins/canvas/public/expression_types/datasources/esdocs.js b/x-pack/legacy/plugins/canvas/public/expression_types/datasources/esdocs.js index ead7f58a851ba..ced1c51496d46 100644 --- a/x-pack/legacy/plugins/canvas/public/expression_types/datasources/esdocs.js +++ b/x-pack/legacy/plugins/canvas/public/expression_types/datasources/esdocs.js @@ -35,7 +35,7 @@ const EsdocsDatasource = ({ args, updateArgs, defaultIndex }) => { }; const getIndex = () => { - return getSimpleArg('index', args)[0] || defaultIndex; + return getSimpleArg('index', args)[0] || ''; }; const getQuery = () => { @@ -58,7 +58,11 @@ const EsdocsDatasource = ({ args, updateArgs, defaultIndex }) => { const fields = getFields(); const [sortField, sortOrder] = getSortBy(); - const index = getIndex().toLowerCase(); + const index = getIndex(); + + if (!index && defaultIndex) { + setArg('index', defaultIndex); + } const sortOptions = [{ value: 'asc', text: 'Ascending' }, { value: 'desc', text: 'Descending' }]; diff --git a/x-pack/legacy/plugins/canvas/public/lib/es_service.js b/x-pack/legacy/plugins/canvas/public/lib/es_service.js index d94ef0d518a06..6a6f4073b065a 100644 --- a/x-pack/legacy/plugins/canvas/public/lib/es_service.js +++ b/x-pack/legacy/plugins/canvas/public/lib/es_service.js @@ -42,8 +42,13 @@ export const getIndices = () => }) .catch(err => notify.error(err, { title: `Couldn't fetch Elasticsearch indices` })); -export const getDefaultIndex = () => - savedObjectsClient - .get('index-pattern', AdvancedSettings.get('defaultIndex')) - .then(defaultIndex => defaultIndex.attributes.title) - .catch(err => notify.error(err, { title: `Couldn't fetch default index` })); +export const getDefaultIndex = () => { + const defaultIndexId = AdvancedSettings.get('defaultIndex'); + + return defaultIndexId + ? savedObjectsClient + .get('index-pattern', defaultIndexId) + .then(defaultIndex => defaultIndex.attributes.title) + .catch(err => notify.error(err, { title: `Couldn't fetch default index` })) + : Promise.resolve(''); +};