From ae7d3e4c6fd9a1471c998ff4626a4a0faf2596ee Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Tue, 12 Feb 2019 19:59:17 -0800 Subject: [PATCH] Remove type filter helper (#30887) (#30908) * Remove type filter helper. This is no longer required in ES 7.0 onwards. * Remove more usages of filter helper --- .../server/lib/__tests__/create_query.js | 19 +++------------ .../lib/beats/__tests__/create_beats_query.js | 9 ++++---- .../lib/cluster/flag_supported_clusters.js | 3 +-- .../server/lib/cluster/get_clusters_state.js | 3 +-- .../monitoring/server/lib/create_query.js | 23 +------------------ 5 files changed, 10 insertions(+), 47 deletions(-) diff --git a/x-pack/plugins/monitoring/server/lib/__tests__/create_query.js b/x-pack/plugins/monitoring/server/lib/__tests__/create_query.js index fcb653bd41c35..8ad0e4e5a953e 100644 --- a/x-pack/plugins/monitoring/server/lib/__tests__/create_query.js +++ b/x-pack/plugins/monitoring/server/lib/__tests__/create_query.js @@ -8,23 +8,10 @@ import expect from 'expect.js'; import { set } from 'lodash'; import { MissingRequiredError } from '../error_missing_required'; import { ElasticsearchMetric } from '../metrics'; -import { createTypeFilter, createQuery } from '../create_query.js'; +import { createQuery } from '../create_query.js'; let metric; - -describe('Create Type Filter', () => { - it('Builds a type filter syntax', () => { - const typeFilter = createTypeFilter('my_type'); - expect(typeFilter).to.eql({ - bool: { should: [ - { term: { _type: 'my_type' } }, - { term: { type: 'my_type' } } - ] } - }); - }); -}); - describe('Create Query', () => { beforeEach(() => { metric = ElasticsearchMetric.getMetricFields(); @@ -97,7 +84,7 @@ describe('Create Query', () => { const options = { type: 'test-type-yay', metric }; const result = createQuery(options); let expected = {}; - expected = set(expected, 'bool.filter[0].bool.should', [ { term: { _type: 'test-type-yay' } }, { term: { type: 'test-type-yay' } } ]); + expected = set(expected, 'bool.filter[0].term', { type: 'test-type-yay' }); expect(result).to.be.eql(expected); }); @@ -111,7 +98,7 @@ describe('Create Query', () => { }; const result = createQuery(options); let expected = {}; - expected = set(expected, 'bool.filter[0].bool.should', [ { term: { _type: 'test-type-yay' } }, { term: { type: 'test-type-yay' } } ]); + expected = set(expected, 'bool.filter[0].term', { type: 'test-type-yay' }); expected = set(expected, 'bool.filter[1].term', { 'source_node.uuid': 'abc123' }); diff --git a/x-pack/plugins/monitoring/server/lib/beats/__tests__/create_beats_query.js b/x-pack/plugins/monitoring/server/lib/beats/__tests__/create_beats_query.js index b4e08920b86d5..0e6c8ba53aa23 100644 --- a/x-pack/plugins/monitoring/server/lib/beats/__tests__/create_beats_query.js +++ b/x-pack/plugins/monitoring/server/lib/beats/__tests__/create_beats_query.js @@ -5,7 +5,6 @@ */ import expect from 'expect.js'; -import { createTypeFilter } from '../../create_query'; import { createBeatsQuery } from '../create_beats_query'; describe('createBeatsQuery', () => { @@ -24,9 +23,9 @@ describe('createBeatsQuery', () => { const query1 = createBeatsQuery(); const query2 = createBeatsQuery({}); - expect(query1.bool.filter[0]).to.eql(createTypeFilter('beats_stats')); + expect(query1.bool.filter[0]).to.eql({ term: { type: 'beats_stats' } }); expect(query1.bool.filter[query1.bool.filter.length - 1]).to.eql(noApmFilter); - expect(query2.bool.filter[0]).to.eql(createTypeFilter('beats_stats')); + expect(query2.bool.filter[0]).to.eql({ term: { type: 'beats_stats' } }); expect(query2.bool.filter[query2.bool.filter.length - 1]).to.eql(noApmFilter); }); @@ -44,7 +43,7 @@ describe('createBeatsQuery', () => { const queryFilters = query.bool.filter; const filterCount = queryFilters.length; - expect(queryFilters[0]).to.eql(createTypeFilter('beats_stats')); + expect(queryFilters[0]).to.eql({ term: { type: 'beats_stats' } }); filters.forEach((filter, index) => { // "custom" filters are added at the end of all known filters, and the last "custom" filter is the noApmFilter @@ -55,4 +54,4 @@ describe('createBeatsQuery', () => { }); }); -}); \ No newline at end of file +}); diff --git a/x-pack/plugins/monitoring/server/lib/cluster/flag_supported_clusters.js b/x-pack/plugins/monitoring/server/lib/cluster/flag_supported_clusters.js index 056a7a794c595..ac377ac2b463e 100644 --- a/x-pack/plugins/monitoring/server/lib/cluster/flag_supported_clusters.js +++ b/x-pack/plugins/monitoring/server/lib/cluster/flag_supported_clusters.js @@ -6,7 +6,6 @@ import { get, set, find } from 'lodash'; import { checkParam } from '../error_missing_required'; -import { createTypeFilter } from '../create_query'; import { LOGGING_TAG, STANDALONE_CLUSTER_CLUSTER_UUID } from '../../../common/constants'; async function findSupportedBasicLicenseCluster(req, clusters, kbnIndexPattern, kibanaUuid, serverLog) { @@ -29,7 +28,7 @@ async function findSupportedBasicLicenseCluster(req, clusters, kbnIndexPattern, query: { bool: { filter: [ - { ...createTypeFilter('kibana_stats') }, + { term: { type: 'kibana_stats' } }, { term: { 'kibana_stats.kibana.uuid': kibanaUuid } }, { range: { timestamp: { gte, lte, format: 'strict_date_optional_time' } } } ] diff --git a/x-pack/plugins/monitoring/server/lib/cluster/get_clusters_state.js b/x-pack/plugins/monitoring/server/lib/cluster/get_clusters_state.js index ea8ab18313241..b1c1c421751a5 100644 --- a/x-pack/plugins/monitoring/server/lib/cluster/get_clusters_state.js +++ b/x-pack/plugins/monitoring/server/lib/cluster/get_clusters_state.js @@ -6,7 +6,6 @@ import { get, find } from 'lodash'; import { checkParam } from '../error_missing_required'; -import { createTypeFilter } from '../create_query'; /** * Augment the {@clusters} with their cluster state's from the {@code response}. @@ -64,7 +63,7 @@ export function getClustersState(req, esIndexPattern, clusters) { query: { bool: { filter: [ - { ...createTypeFilter('cluster_state') }, + { term: { type: 'cluster_state' } }, { terms: { 'cluster_uuid': clusterUuids } } ] } diff --git a/x-pack/plugins/monitoring/server/lib/create_query.js b/x-pack/plugins/monitoring/server/lib/create_query.js index 44b6a6b98c21e..941875e1734a5 100644 --- a/x-pack/plugins/monitoring/server/lib/create_query.js +++ b/x-pack/plugins/monitoring/server/lib/create_query.js @@ -10,31 +10,10 @@ import moment from 'moment'; import { standaloneClusterFilter } from './standalone_clusters'; import { STANDALONE_CLUSTER_CLUSTER_UUID } from '../../common/constants'; -/* - * Builds a type filter syntax that supports backwards compatibility to read - * from indices before and after `_type` is removed from Elasticsearch - * - * TODO: this backwards compatibility helper will only be supported for 5.x-6. This - * function should be removed in 7.0 - */ -export const createTypeFilter = (type) => { - return { - bool: { - should: [ - { term: { _type: type } }, - { term: { type } } - ] - } - }; -}; - /* * Creates the boilerplace for querying monitoring data, including filling in * document UUIDs, start time and end time, and injecting additional filters. * - * Create a bool for types that will query for documents using `_type` (true type) and `type` (as a field) - * Makes backwards compatibility for types being deprecated in Elasticsearch - * * Options object: * @param {String} options.type - `type` field value of the documents * @param {Array} options.filters - additional filters to add to the `bool` section of the query. Default: [] @@ -52,7 +31,7 @@ export function createQuery(options) { let typeFilter; if (type) { - typeFilter = createTypeFilter(type); + typeFilter = { term: { type } }; } let clusterUuidFilter;