From af07ba0daf803cb19d2689647de5fa2518f1430f Mon Sep 17 00:00:00 2001 From: Hailong Cui Date: Tue, 17 Oct 2023 17:29:53 +0800 Subject: [PATCH] Add simple string query flags options to find method Signed-off-by: Hailong Cui --- src/core/server/saved_objects/service/lib/repository.ts | 2 ++ .../saved_objects/service/lib/search_dsl/query_params.ts | 6 ++++++ .../saved_objects/service/lib/search_dsl/search_dsl.ts | 3 +++ src/core/server/saved_objects/types.ts | 2 ++ src/plugins/workspace/server/workspace_client.ts | 2 ++ 5 files changed, 15 insertions(+) diff --git a/src/core/server/saved_objects/service/lib/repository.ts b/src/core/server/saved_objects/service/lib/repository.ts index a8fd54ef6cfe..3ee7889475d2 100644 --- a/src/core/server/saved_objects/service/lib/repository.ts +++ b/src/core/server/saved_objects/service/lib/repository.ts @@ -888,6 +888,7 @@ export class SavedObjectsRepository { preference, workspaces, ACLSearchParams, + flags, } = options; if (!type && !typeToNamespacesMap) { @@ -963,6 +964,7 @@ export class SavedObjectsRepository { kueryNode, workspaces, ACLSearchParams, + flags, }), }, }; diff --git a/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts b/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts index 96da76df5a68..4f2170abad22 100644 --- a/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts +++ b/src/core/server/saved_objects/service/lib/search_dsl/query_params.ts @@ -168,6 +168,7 @@ interface QueryParams { kueryNode?: KueryNode; workspaces?: string[]; ACLSearchParams?: SavedObjectsFindOptions['ACLSearchParams']; + flags?: string; } export function getClauseForReference(reference: HasReferenceQueryParams) { @@ -226,6 +227,7 @@ export function getQueryParams({ kueryNode, workspaces, ACLSearchParams, + flags, }: QueryParams) { const types = getTypes( registry, @@ -269,6 +271,7 @@ export function getQueryParams({ searchFields, rootSearchFields, defaultSearchOperator, + flags, }); if (useMatchPhrasePrefix) { @@ -417,18 +420,21 @@ const getSimpleQueryStringClause = ({ searchFields, rootSearchFields, defaultSearchOperator, + flags, }: { search: string; types: string[]; searchFields?: string[]; rootSearchFields?: string[]; defaultSearchOperator?: string; + flags?: string; }) => { return { simple_query_string: { query: search, ...getSimpleQueryStringTypeFields(types, searchFields, rootSearchFields), ...(defaultSearchOperator ? { default_operator: defaultSearchOperator } : {}), + ...(flags ? { flags } : {}), }, }; }; diff --git a/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.ts b/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.ts index a93e134a9757..ba8caff62401 100644 --- a/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.ts +++ b/src/core/server/saved_objects/service/lib/search_dsl/search_dsl.ts @@ -55,6 +55,7 @@ interface GetSearchDslOptions { kueryNode?: KueryNode; workspaces?: string[]; ACLSearchParams?: SavedObjectsFindOptions['ACLSearchParams']; + flags?: string; } export function getSearchDsl( @@ -76,6 +77,7 @@ export function getSearchDsl( kueryNode, workspaces, ACLSearchParams, + flags, } = options; if (!type) { @@ -100,6 +102,7 @@ export function getSearchDsl( kueryNode, workspaces, ACLSearchParams, + flags, }), ...getSortingParams(mappings, type, sortField, sortOrder), }; diff --git a/src/core/server/saved_objects/types.ts b/src/core/server/saved_objects/types.ts index aa2d1baf85de..90ffcd311fca 100644 --- a/src/core/server/saved_objects/types.ts +++ b/src/core/server/saved_objects/types.ts @@ -92,6 +92,8 @@ export interface SavedObjectsFindOptions { search?: string; /** The fields to perform the parsed query against. See OpenSearch Simple Query String `fields` argument for more information */ searchFields?: string[]; + /** The enabled operators for OpenSearch Simple Query String. See OpenSearch Simple Query String `flags` argument for more information */ + flags?: string; /** * The fields to perform the parsed query against. Unlike the `searchFields` argument, these are expected to be root fields and will not * be modified. If used in conjunction with `searchFields`, both are concatenated together. diff --git a/src/plugins/workspace/server/workspace_client.ts b/src/plugins/workspace/server/workspace_client.ts index ff9bd9a06cb1..fcc92a2e8edd 100644 --- a/src/plugins/workspace/server/workspace_client.ts +++ b/src/plugins/workspace/server/workspace_client.ts @@ -202,6 +202,7 @@ export class WorkspaceClientWithSavedObject implements IWorkspaceDBImpl { type: WORKSPACE_TYPE, search: attributes.name, searchFields: ['name'], + flags: 'NONE', // disable all operators, treat workspace as literal string } ); if (existingWorkspaceRes && existingWorkspaceRes.total > 0) { @@ -353,6 +354,7 @@ export class WorkspaceClientWithSavedObject implements IWorkspaceDBImpl { search: attributes.name, searchFields: ['name'], fields: ['_id'], + flags: 'NONE', // disable all operators, treat workspace as literal string }); if (existingWorkspaceRes && existingWorkspaceRes.total > 0) { throw new Error(DUPLICATE_WORKSPACE_NAME_ERROR);