[Maps] apply filters to join SearchSource request (#34072)
* [Maps] apply filters to join SearchSource request * add functional test verify filter applied to join in dashboard
This commit is contained in:
parent
1d2fbf827c
commit
d6eb59179f
|
@ -8,12 +8,7 @@ import _ from 'lodash';
|
|||
|
||||
import { AbstractESSource } from './es_source';
|
||||
import { Schemas } from 'ui/vis/editors/default/schemas';
|
||||
import {
|
||||
fetchSearchSourceAndRecordWithInspector,
|
||||
SearchSource,
|
||||
} from '../../../kibana_services';
|
||||
import { AggConfigs } from 'ui/vis/agg_configs';
|
||||
import { timefilter } from 'ui/timefilter/timefilter';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
|
||||
const TERMS_AGG_NAME = 'join';
|
||||
|
@ -96,42 +91,14 @@ export class ESJoinSource extends AbstractESSource {
|
|||
}
|
||||
|
||||
const indexPattern = await this._getIndexPattern();
|
||||
const timeAware = await this.isTimeAware();
|
||||
|
||||
const searchSource = await this._makeSearchSource(searchFilters, 0);
|
||||
const configStates = this._makeAggConfigs();
|
||||
const aggConfigs = new AggConfigs(indexPattern, configStates, aggSchemas.all);
|
||||
searchSource.setField('aggs', aggConfigs.toDsl());
|
||||
|
||||
let rawEsData;
|
||||
try {
|
||||
const searchSource = new SearchSource();
|
||||
searchSource.setField('index', indexPattern);
|
||||
searchSource.setField('size', 0);
|
||||
searchSource.setField('filter', () => {
|
||||
const filters = [];
|
||||
if (timeAware) {
|
||||
filters.push(timefilter.createFilter(indexPattern, searchFilters.timeFilters));
|
||||
}
|
||||
return filters;
|
||||
});
|
||||
searchSource.setField('query', searchFilters.query);
|
||||
|
||||
const dsl = aggConfigs.toDsl();
|
||||
searchSource.setField('aggs', dsl);
|
||||
rawEsData = await fetchSearchSourceAndRecordWithInspector({
|
||||
inspectorAdapters: this._inspectorAdapters,
|
||||
searchSource,
|
||||
requestName: `${this._descriptor.indexPatternTitle}.${this._descriptor.term}`,
|
||||
requestId: this._descriptor.id,
|
||||
requestDesc: this.getJoinDescription(leftSourceName, leftFieldName),
|
||||
});
|
||||
} catch (error) {
|
||||
throw new Error(i18n.translate('xpack.maps.source.esJoin.errorMessage', {
|
||||
defaultMessage: `Elasticsearch search request failed, error: {message}`,
|
||||
values: {
|
||||
message: error.message
|
||||
}
|
||||
}));
|
||||
}
|
||||
const requestName = `${this._descriptor.indexPatternTitle}.${this._descriptor.term}`;
|
||||
const requestDesc = this.getJoinDescription(leftSourceName, leftFieldName);
|
||||
const rawEsData = await this._runEsQuery(requestName, searchSource, requestDesc);
|
||||
|
||||
const metricPropertyNames = configStates
|
||||
.filter(configState => {
|
||||
|
|
|
@ -131,12 +131,12 @@ export class AbstractESSource extends AbstractVectorSource {
|
|||
}
|
||||
|
||||
|
||||
async _runEsQuery(layerName, searchSource, requestDescription) {
|
||||
async _runEsQuery(requestName, searchSource, requestDescription) {
|
||||
try {
|
||||
return await fetchSearchSourceAndRecordWithInspector({
|
||||
inspectorAdapters: this._inspectorAdapters,
|
||||
searchSource,
|
||||
requestName: layerName,
|
||||
requestName,
|
||||
requestId: this._descriptor.id,
|
||||
requestDesc: requestDescription
|
||||
});
|
||||
|
@ -150,21 +150,20 @@ export class AbstractESSource extends AbstractVectorSource {
|
|||
|
||||
async _makeSearchSource(searchFilters, limit) {
|
||||
const indexPattern = await this._getIndexPattern();
|
||||
const geoField = await this._getGeoField();
|
||||
const isTimeAware = await this.isTimeAware();
|
||||
const allFilters = [...searchFilters.filters];
|
||||
if (this.isFilterByMapBounds() && searchFilters.buffer) {//buffer can be empty
|
||||
const geoField = await this._getGeoField();
|
||||
allFilters.push(createExtentFilter(searchFilters.buffer, geoField.name, geoField.type));
|
||||
}
|
||||
if (isTimeAware) {
|
||||
allFilters.push(timefilter.createFilter(indexPattern, searchFilters.timeFilters));
|
||||
}
|
||||
|
||||
const searchSource = new SearchSource();
|
||||
searchSource.setField('index', indexPattern);
|
||||
searchSource.setField('size', limit);
|
||||
searchSource.setField('filter', () => {
|
||||
const allFilters = [...searchFilters.filters];
|
||||
if (this.isFilterByMapBounds() && searchFilters.buffer) {//buffer can be empty
|
||||
allFilters.push(createExtentFilter(searchFilters.buffer, geoField.name, geoField.type));
|
||||
}
|
||||
if (isTimeAware) {
|
||||
allFilters.push(timefilter.createFilter(indexPattern, searchFilters.timeFilters));
|
||||
}
|
||||
return allFilters;
|
||||
});
|
||||
searchSource.setField('filter', allFilters);
|
||||
searchSource.setField('query', searchFilters.query);
|
||||
|
||||
if (searchFilters.layerQuery) {
|
||||
|
|
|
@ -228,7 +228,7 @@ export class VectorLayer extends AbstractLayer {
|
|||
&& !updateDueToPrecisionChange;
|
||||
}
|
||||
|
||||
async _syncJoin(join, { startLoading, stopLoading, onLoadError, dataFilters }) {
|
||||
async _syncJoin({ join, startLoading, stopLoading, onLoadError, dataFilters }) {
|
||||
|
||||
const joinSource = join.getJoinSource();
|
||||
const sourceDataId = join.getSourceId();
|
||||
|
@ -269,7 +269,7 @@ export class VectorLayer extends AbstractLayer {
|
|||
|
||||
async _syncJoins({ startLoading, stopLoading, onLoadError, dataFilters }) {
|
||||
const joinSyncs = this.getValidJoins().map(async join => {
|
||||
return this._syncJoin(join, { startLoading, stopLoading, onLoadError, dataFilters });
|
||||
return this._syncJoin({ join, startLoading, stopLoading, onLoadError, dataFilters });
|
||||
});
|
||||
return await Promise.all(joinSyncs);
|
||||
}
|
||||
|
|
|
@ -12,16 +12,24 @@ export default function ({ getPageObjects, getService }) {
|
|||
const filterBar = getService('filterBar');
|
||||
const dashboardPanelActions = getService('dashboardPanelActions');
|
||||
const inspector = getService('inspector');
|
||||
const testSubjects = getService('testSubjects');
|
||||
|
||||
describe('embed in dashboard', () => {
|
||||
before(async () => {
|
||||
await kibanaServer.uiSettings.replace({
|
||||
'defaultIndex': 'c698b940-e149-11e8-a35a-370a8516603a'
|
||||
'defaultIndex': 'c698b940-e149-11e8-a35a-370a8516603a',
|
||||
'courier:ignoreFilterIfFieldNotInIndex': true
|
||||
});
|
||||
await PageObjects.common.navigateToApp('dashboard');
|
||||
await PageObjects.dashboard.loadSavedDashboard('map embeddable example');
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await kibanaServer.uiSettings.replace({
|
||||
'courier:ignoreFilterIfFieldNotInIndex': false
|
||||
});
|
||||
});
|
||||
|
||||
async function getRequestTimestamp() {
|
||||
await inspector.openInspectorRequestsView();
|
||||
const requestStats = await inspector.getTableData();
|
||||
|
@ -58,11 +66,22 @@ export default function ({ getPageObjects, getService }) {
|
|||
it('should apply new container state (time, query, filters) to embeddable', async () => {
|
||||
await filterBar.selectIndexPattern('logstash-*');
|
||||
await filterBar.addFilter('machine.os', 'is', 'win 8');
|
||||
await filterBar.selectIndexPattern('meta_for_geo_shapes*');
|
||||
await filterBar.addFilter('shape_name', 'is', 'alpha');
|
||||
|
||||
await dashboardPanelActions.openInspectorByTitle('geo grid vector grid example');
|
||||
const requestStats = await inspector.getTableData();
|
||||
const totalHits = PageObjects.maps.getInspectorStatRowHit(requestStats, 'Hits (total)');
|
||||
const geoGridRequestStats = await inspector.getTableData();
|
||||
const geoGridTotalHits = PageObjects.maps.getInspectorStatRowHit(geoGridRequestStats, 'Hits (total)');
|
||||
await inspector.close();
|
||||
expect(totalHits).to.equal('1');
|
||||
expect(geoGridTotalHits).to.equal('1');
|
||||
|
||||
await dashboardPanelActions.openInspectorByTitle('join example');
|
||||
await testSubjects.click('inspectorRequestChooser');
|
||||
await testSubjects.click('inspectorRequestChoosermeta_for_geo_shapes*.shape_name');
|
||||
const joinRequestStats = await inspector.getTableData();
|
||||
const joinTotalHits = PageObjects.maps.getInspectorStatRowHit(joinRequestStats, 'Hits (total)');
|
||||
await inspector.close();
|
||||
expect(joinTotalHits).to.equal('3');
|
||||
});
|
||||
|
||||
it('should re-fetch query when "refresh" is clicked', async () => {
|
||||
|
|
Loading…
Reference in a new issue