Skip to content

Commit

Permalink
Support verbose search bwc
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler committed Feb 11, 2025
1 parent 6a306be commit c1e09ee
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
13 changes: 13 additions & 0 deletions public/pages/workflow_detail/tools/query/query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
containsEmptyValues,
containsSameValues,
getDataSourceId,
getEffectiveVersion,
getPlaceholdersFromQuery,
getSearchPipelineErrors,
injectParameters,
Expand Down Expand Up @@ -64,6 +65,17 @@ const SEARCH_OPTIONS = [
export function Query(props: QueryProps) {
const dispatch = useAppDispatch();
const dataSourceId = getDataSourceId();
const [dataSourceVersion, setDataSourceVersion] = useState<
string | undefined
>(undefined);
useEffect(() => {
async function getVersion() {
if (dataSourceId !== undefined) {
setDataSourceVersion(await getEffectiveVersion(dataSourceId));
}
}
getVersion();
}, [dataSourceId]);

const { loading } = useSelector((state: AppState) => state.opensearch);

Expand Down Expand Up @@ -204,6 +216,7 @@ export function Query(props: QueryProps) {
: '_none',
},
dataSourceId,
dataSourceVersion,
verbose: includePipeline,
})
)
Expand Down
6 changes: 5 additions & 1 deletion public/route_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {
INGEST_PIPELINE_NODE_API_PATH,
GET_INDEX_NODE_API_PATH,
} from '../common';
import { getEffectiveVersion } from './utils';

/**
* A simple client-side service interface containing all of the available node API functions.
Expand Down Expand Up @@ -99,12 +98,14 @@ export interface RouteService {
index,
body,
dataSourceId,
dataSourceVersion,
searchPipeline,
verbose,
}: {
index: string;
body: {};
dataSourceId?: string;
dataSourceVersion?: string;
searchPipeline?: string;
verbose?: boolean;
}) => Promise<any | HttpFetchError>;
Expand Down Expand Up @@ -339,12 +340,14 @@ export function configureRoutes(core: CoreStart): RouteService {
index,
body,
dataSourceId,
dataSourceVersion,
searchPipeline,
verbose,
}: {
index: string;
body: {};
dataSourceId?: string;
dataSourceVersion?: string;
searchPipeline?: string;
verbose?: boolean;
}) => {
Expand All @@ -360,6 +363,7 @@ export function configureRoutes(core: CoreStart): RouteService {
body: JSON.stringify(body),
query: {
verbose: verbose ?? false,
data_source_version: dataSourceVersion,
},
});
return response;
Expand Down
3 changes: 3 additions & 0 deletions public/store/reducers/opensearch_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ export const searchIndex = createAsyncThunk(
{
apiBody,
dataSourceId,
dataSourceVersion,
verbose,
}: {
apiBody: { index: string; body: {}; searchPipeline?: string };
dataSourceId?: string;
dataSourceVersion?: string;
verbose?: boolean;
},
{ rejectWithValue }
Expand All @@ -123,6 +125,7 @@ export const searchIndex = createAsyncThunk(
index,
body,
dataSourceId,
dataSourceVersion,
searchPipeline,
verbose,
});
Expand Down
34 changes: 26 additions & 8 deletions server/routes/opensearch_routes_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { schema } from '@osd/config-schema';
import { isEmpty } from 'lodash';
import semver from 'semver';
import {
IRouter,
IOpenSearchDashboardsResponse,
Expand All @@ -25,6 +26,7 @@ import {
IndexResponse,
IngestPipelineConfig,
IngestPipelineResponse,
MINIMUM_FULL_SUPPORTED_VERSION,
SEARCH_INDEX_NODE_API_PATH,
SEARCH_PIPELINE_NODE_API_PATH,
SIMULATE_PIPELINE_NODE_API_PATH,
Expand Down Expand Up @@ -138,6 +140,7 @@ export function registerOpenSearchRoutes(
body: schema.any(),
query: schema.object({
verbose: schema.boolean(),
data_source_version: schema.string(),
}),
},
},
Expand Down Expand Up @@ -171,6 +174,7 @@ export function registerOpenSearchRoutes(
body: schema.any(),
query: schema.object({
verbose: schema.boolean(),
data_source_version: schema.string(),
}),
},
},
Expand Down Expand Up @@ -479,9 +483,14 @@ export class OpenSearchRoutesService {
search_pipeline: string | undefined;
};
const { data_source_id = '' } = req.params as { data_source_id?: string };
const { verbose = false } = req.query as {
const { verbose = false, data_source_version = undefined } = req.query as {
verbose?: boolean;
data_source_version?: string;
};
const isPreV219 =
data_source_version !== undefined
? semver.lt(data_source_version, MINIMUM_FULL_SUPPORTED_VERSION)
: false;
const body = req.body;
try {
const callWithRequest = getClientBasedOnDataSource(
Expand All @@ -491,13 +500,22 @@ export class OpenSearchRoutesService {
data_source_id,
this.client
);

const response = await callWithRequest('search', {
index,
body,
search_pipeline,
verbose_pipeline: verbose,
});
let response;
// If verbose is false/undefined, or the version isn't eligible, omit the verbose param when searching.
if (!verbose || isPreV219) {
response = await callWithRequest('search', {
index,
body,
search_pipeline,
});
} else {
response = await callWithRequest('search', {
index,
body,
search_pipeline,
verbose_pipeline: verbose,
});
}

return res.ok({ body: response });
} catch (err: any) {
Expand Down

0 comments on commit c1e09ee

Please sign in to comment.