mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[Fleet] Agent policy search, support simple text filter. (#107306)
* feat: fall back to simple search on parse error * fix: simplify query * lint: fix docs Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
5cd7358834
commit
48a97f6d18
2 changed files with 22 additions and 6 deletions
|
@ -333,14 +333,30 @@ class AgentPolicyService {
|
|||
withPackagePolicies = false,
|
||||
} = options;
|
||||
|
||||
const agentPoliciesSO = await soClient.find<AgentPolicySOAttributes>({
|
||||
const baseFindParams = {
|
||||
type: SAVED_OBJECT_TYPE,
|
||||
sortField,
|
||||
sortOrder,
|
||||
page,
|
||||
perPage,
|
||||
filter: kuery ? normalizeKuery(SAVED_OBJECT_TYPE, kuery) : undefined,
|
||||
});
|
||||
};
|
||||
const filter = kuery ? normalizeKuery(SAVED_OBJECT_TYPE, kuery) : undefined;
|
||||
let agentPoliciesSO;
|
||||
try {
|
||||
agentPoliciesSO = await soClient.find<AgentPolicySOAttributes>({ ...baseFindParams, filter });
|
||||
} catch (e) {
|
||||
const isBadRequest = e.output?.statusCode === 400;
|
||||
const isKQLSyntaxError = e.message?.startsWith('KQLSyntaxError');
|
||||
if (isBadRequest && !isKQLSyntaxError) {
|
||||
// fall back to simple search if the kuery is just a search term i.e not KQL
|
||||
agentPoliciesSO = await soClient.find<AgentPolicySOAttributes>({
|
||||
...baseFindParams,
|
||||
search: kuery,
|
||||
});
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
const agentPolicies = await Promise.all(
|
||||
agentPoliciesSO.saved_objects.map(async (agentPolicySO) => {
|
||||
|
|
|
@ -19,9 +19,9 @@ export function escapeSearchQueryPhrase(val: string): string {
|
|||
return `"${val.replace(/["]/g, '"')}"`;
|
||||
}
|
||||
|
||||
// Adds `.attribute` to any kuery strings that are missing it, this comes from
|
||||
// internal SO structure. Kuery strings that come from UI will typicall have
|
||||
// `.attribute` hidden to simplify UX, so this normalizes any kuery string for
|
||||
// Adds `.attributes` to any kuery strings that are missing it, this comes from
|
||||
// internal SO structure. Kuery strings that come from UI will typically have
|
||||
// `.attributes` hidden to simplify UX, so this normalizes any kuery string for
|
||||
// filtering SOs
|
||||
export const normalizeKuery = (savedObjectType: string, kuery: string): string => {
|
||||
return kuery.replace(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue