-
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.
Fix SO management fulltext search (#154409)
## Summary Fix #154244 Related / workaround for #130616 Very old issue that happened again, this time for the `slo` type because of mapping incompatibilities with default searchable fields (and a limitation in our code we still did not address) - Fix the `slo` SO type mapping for the `name` field (keyword => text) - Add a integration test failing if any management type has incorrect mappings for searchable fields (mostly a workaround rather than fixing the root problem, but at least it will avoid that kind of scenario for the time being)
- Loading branch information
1 parent
595c6e0
commit 8de96ea
Showing
4 changed files
with
88 additions
and
3 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
75 changes: 75 additions & 0 deletions
75
...re/server/integration_tests/saved_objects/migrations/group3/default_search_fields.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,75 @@ | ||
/* | ||
* 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 { createRoot } from '@kbn/core-test-helpers-kbn-server'; | ||
|
||
describe('SO default search fields', () => { | ||
let root: ReturnType<typeof createRoot>; | ||
|
||
afterEach(() => { | ||
try { | ||
root?.shutdown(); | ||
} catch (e) { | ||
/* trap */ | ||
} | ||
}); | ||
|
||
interface InvalidMappingTuple { | ||
type: string; | ||
field: string; | ||
} | ||
|
||
// identify / avoid scenarios of https://github.com/elastic/kibana/issues/130616 | ||
it('make sure management types have the correct mappings for default search fields', async () => { | ||
root = createRoot({}, { oss: false }); | ||
await root.preboot(); | ||
const setup = await root.setup(); | ||
|
||
const allTypes = setup.savedObjects.getTypeRegistry().getAllTypes(); | ||
|
||
const defaultSearchFields = [ | ||
...allTypes.reduce((fieldSet, type) => { | ||
if (type.management?.defaultSearchField) { | ||
fieldSet.add(type.management.defaultSearchField); | ||
} | ||
return fieldSet; | ||
}, new Set<string>()), | ||
]; | ||
|
||
const invalidMappings: InvalidMappingTuple[] = []; | ||
|
||
const managementTypes = setup.savedObjects | ||
.getTypeRegistry() | ||
.getImportableAndExportableTypes() | ||
.filter((type) => type.management!.visibleInManagement ?? true); | ||
|
||
managementTypes.forEach((type) => { | ||
const mappingProps = type.mappings.properties; | ||
defaultSearchFields.forEach((searchField) => { | ||
if (mappingProps[searchField]) { | ||
const fieldDef = mappingProps[searchField]; | ||
if (fieldDef.type !== 'text') { | ||
invalidMappings.push({ | ||
type: type.name, | ||
field: searchField, | ||
}); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
if (invalidMappings.length > 0) { | ||
// `fail()` no longer exists... | ||
expect( | ||
`fields registered as defaultSearchField by any type must be registered as text. Invalid mappings found: ${JSON.stringify( | ||
invalidMappings | ||
)}` | ||
).toEqual(''); | ||
} | ||
}); | ||
}); |
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