-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Security Solution] Only apply field aliases to legacy .siem-signals indices #115290
Changes from 6 commits
81a899d
0025cf7
c462a00
0961a04
f419b3c
6f35eae
a0d11fd
e5c860e
69eb783
4623144
e3ebdfa
bffab2a
fb5e0da
3e72cd0
1532ae9
d61a8f7
bc1ee67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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 { ElasticsearchClient } from '../elasticsearch_client'; | ||
|
||
/** | ||
* This function is similar to getIndexExists, but is limited to searching indices that match | ||
* the index pattern used as concrete backing indices (e.g. .siem-signals-default-000001). | ||
* This allows us to separate the indices that are actually .siem-signals indices from | ||
* alerts as data indices that only share the .siem-signals alias. | ||
* | ||
* @param esClient Elasticsearch client to use to make the request | ||
* @param index Index alias name to check for existence | ||
*/ | ||
export const getBootstrapIndexExists = async ( | ||
esClient: ElasticsearchClient, | ||
index: string | ||
): Promise<boolean> => { | ||
try { | ||
const { body } = await esClient.indices.getAlias({ | ||
index: `${index}-*`, | ||
name: index, | ||
}); | ||
return Object.keys(body).length > 0; | ||
} catch (err) { | ||
if (err.body != null && err.body.status === 404) { | ||
return false; | ||
} else { | ||
throw err.body ? err.body : err; | ||
} | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
* 2.0. | ||
*/ | ||
|
||
import { transformError, getIndexExists } from '@kbn/securitysolution-es-utils'; | ||
import { transformError, getBootstrapIndexExists } from '@kbn/securitysolution-es-utils'; | ||
import { parseExperimentalConfigValue } from '../../../../../common/experimental_features'; | ||
import { ConfigType } from '../../../../config'; | ||
import type { SecuritySolutionPluginRouter } from '../../../../types'; | ||
|
@@ -41,7 +41,10 @@ export const readIndexRoute = (router: SecuritySolutionPluginRouter, config: Con | |
const { ruleRegistryEnabled } = parseExperimentalConfigValue(config.enableExperimental); | ||
|
||
const index = siemClient.getSignalsIndex(); | ||
const indexExists = await getIndexExists(esClient, index); | ||
const indexExists = await getBootstrapIndexExists( | ||
context.core.elasticsearch.client.asInternalUser, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
index | ||
); | ||
|
||
if (indexExists) { | ||
let mappingOutdated: boolean | null = null; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we do use this code again (most likely for 8.0, so very soon) we'll want to limit this query the same way the
getBootstrapIndexExists
check is limited.