-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[data views] Provide method of excluding data tiers when getting fiel…
…d list (#167946) ## Summary This PR implements an advanced setting that allows the exclusion of listed data tiers when getting a field list. The expected common use case would be excluding frozen indices to speed up slow field caps calls. There is no serverless functionality since serverless doesn't have data tiers.
- Loading branch information
Showing
12 changed files
with
153 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/plugins/data_views/server/rest_api_routes/internal/utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { getIndexFilterDsl } from './utils'; | ||
|
||
describe('getIndexFilterDsl', () => { | ||
const indexFilter = { term: { _id: '1' } }; | ||
const tiersQuery = { | ||
bool: { | ||
must_not: [ | ||
{ | ||
terms: { | ||
_tier: ['data_cold', 'data_frozen'], | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
const excludedTiers = 'data_cold, data_frozen'; | ||
|
||
it('no indexFilter, no excluded tiers', () => { | ||
expect(getIndexFilterDsl({})).toBeUndefined(); | ||
}); | ||
|
||
it('indexFilter, no excluded tiers', () => { | ||
expect(getIndexFilterDsl({ indexFilter })).toEqual(indexFilter); | ||
}); | ||
|
||
it('excluded tiers, no indexFilter', () => { | ||
expect(getIndexFilterDsl({ excludedTiers })).toEqual(tiersQuery); | ||
}); | ||
|
||
it('indexFilter and excluded tiers', () => { | ||
const combinedQuery = { | ||
bool: { | ||
must: [indexFilter, tiersQuery], | ||
}, | ||
}; | ||
|
||
expect(getIndexFilterDsl({ indexFilter, excludedTiers })).toEqual(combinedQuery); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
src/plugins/data_views/server/rest_api_routes/internal/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { QueryDslQueryContainer } from '../../../common/types'; | ||
|
||
const excludeTiersDsl = (excludedTiers: string) => { | ||
const _tier = excludedTiers.split(',').map((tier) => tier.trim()); | ||
return { | ||
bool: { | ||
must_not: [ | ||
{ | ||
terms: { | ||
_tier, | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
}; | ||
|
||
interface GetIndexFilterDslOptions { | ||
indexFilter?: QueryDslQueryContainer; | ||
excludedTiers?: string; | ||
} | ||
|
||
export const getIndexFilterDsl = ({ | ||
indexFilter, | ||
excludedTiers, | ||
}: GetIndexFilterDslOptions): QueryDslQueryContainer | undefined => { | ||
if (!indexFilter) { | ||
return excludedTiers ? excludeTiersDsl(excludedTiers) : undefined; | ||
} | ||
|
||
return !excludedTiers | ||
? indexFilter | ||
: { | ||
bool: { | ||
must: [indexFilter, excludeTiersDsl(excludedTiers)], | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters