diff --git a/src/plugins/vis_type_timeline/server/series_functions/opensearch/index.js b/src/plugins/vis_type_timeline/server/series_functions/opensearch/index.js index dbc3b5483d12..933789fe2d7c 100644 --- a/src/plugins/vis_type_timeline/server/series_functions/opensearch/index.js +++ b/src/plugins/vis_type_timeline/server/series_functions/opensearch/index.js @@ -91,6 +91,14 @@ export default new Datasource('es', { description: '"date" is a field type and should not be translated.', }), }, + { + name: 'kibana', + types: ['boolean', 'null'], + help: i18n.translate('timeline.help.functions.opensearch.args.opensearchDashboardsHelpText', { + defaultMessage: + 'Respect filters on OpenSearch Dashboards dashboards. Only has an effect when using on OpenSearch Dashboards dashboards', + }), + }, { name: 'opensearchDashboards', types: ['boolean', 'null'], @@ -110,7 +118,7 @@ export default new Datasource('es', { help: i18n.translate('timeline.help.functions.opensearchHelpText', { defaultMessage: 'Pull data from an opensearch instance', }), - aliases: ['es'], + aliases: ['elasticsearch', 'opensearch'], fn: async function opensearchFn(args, tlConfig) { const config = _.defaults(_.clone(args.byName), { q: '*', @@ -118,6 +126,7 @@ export default new Datasource('es', { index: tlConfig.settings['timeline:es.default_index'], timefield: tlConfig.settings['timeline:es.timefield'], interval: tlConfig.time.interval, + kibana: true, opensearchDashboards: true, fit: 'nearest', }); diff --git a/src/plugins/vis_type_timeline/server/series_functions/opensearch/lib/build_request.js b/src/plugins/vis_type_timeline/server/series_functions/opensearch/lib/build_request.js index 9a52851a6497..382ebaa757fe 100644 --- a/src/plugins/vis_type_timeline/server/series_functions/opensearch/lib/build_request.js +++ b/src/plugins/vis_type_timeline/server/series_functions/opensearch/lib/build_request.js @@ -50,9 +50,9 @@ export default function buildRequest(config, tlConfig, scriptedFields, timeout) }; bool.must.push(timeFilter); - // Use the opensearchDashboards filter bar filters - if (config.opensearchDashboards) { - bool.filter = _.get(tlConfig, 'request.body.extended.opensearch.filter'); + // Use the opensearchDashboards and kibana filter bar filters + if (config.opensearchDashboards && config.kibana) { + bool.filter = _.get(tlConfig, 'request.body.extended.es.filter'); } const aggs = { diff --git a/src/plugins/vis_type_timeline/server/series_functions/opensearch/opensearch.test.js b/src/plugins/vis_type_timeline/server/series_functions/opensearch/opensearch.test.js index d6d16c81c028..ba93a9e6b3a8 100644 --- a/src/plugins/vis_type_timeline/server/series_functions/opensearch/opensearch.test.js +++ b/src/plugins/vis_type_timeline/server/series_functions/opensearch/opensearch.test.js @@ -264,7 +264,7 @@ describe('opensearch', () => { request: { body: { extended: { - opensearch: { + es: { filter: { bool: { must: [{ query: { query_string: { query: 'foo' } } }], @@ -281,8 +281,9 @@ describe('opensearch', () => { }); }); - it('adds the contents of body.extended.opensearch.filter to a filter clause of the bool', () => { + it('adds the contents of body.extended.es.filter to a filter clause of the bool', () => { config.opensearchDashboards = true; + config.kibana = true; const request = fn(config, tlConfig, emptyScriptedFields); const filter = request.params.body.query.bool.filter.bool; expect(filter.must.length).to.eql(1); @@ -291,6 +292,21 @@ describe('opensearch', () => { it('does not include filters if config.opensearchDashboards = false', () => { config.opensearchDashboards = false; + config.kibana = true; + const request = fn(config, tlConfig, emptyScriptedFields); + expect(request.params.body.query.bool.filter).to.eql(undefined); + }); + + it('does not include filters if config.kibana = false', () => { + config.opensearchDashboards = true; + config.kibana = false; + const request = fn(config, tlConfig, emptyScriptedFields); + expect(request.params.body.query.bool.filter).to.eql(undefined); + }); + + it('does not include filters if config.opensearchDashboards = false and config.kibana = false', () => { + config.opensearchDashboards = false; + config.kibana = false; const request = fn(config, tlConfig, emptyScriptedFields); expect(request.params.body.query.bool.filter).to.eql(undefined); });