From 7987527d31ea25169fd1167c3c7d7132fb3c83f5 Mon Sep 17 00:00:00 2001 From: Joe McElroy Date: Fri, 17 Jan 2025 13:20:04 +0000 Subject: [PATCH] [Search] [Playground] fix semantic_text issue (#207054) ## Summary This fixes an issue in playground where the generated query is using a multi_match. This is because the field is now defined as a text field and Playground was treating the field as a text field and using it in a multi-match. This fix detects if the field is declared in the mappings API as semantic_text and what the model_id is. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> --- .../__mocks__/fetch_query_source_fields.mock.ts | 12 ++++++------ .../server/lib/fetch_query_source_fields.ts | 7 +++---- .../search_playground/server/utils/stream_factory.ts | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/x-pack/solutions/search/plugins/search_playground/__mocks__/fetch_query_source_fields.mock.ts b/x-pack/solutions/search/plugins/search_playground/__mocks__/fetch_query_source_fields.mock.ts index 7ab5f261989a4..7ba2cef9b2b34 100644 --- a/x-pack/solutions/search/plugins/search_playground/__mocks__/fetch_query_source_fields.mock.ts +++ b/x-pack/solutions/search/plugins/search_playground/__mocks__/fetch_query_source_fields.mock.ts @@ -11,10 +11,10 @@ export const SPARSE_SEMANTIC_FIELD_FIELD_CAPS = { indices: ['test-index2'], fields: { infer_field: { - semantic_text: { - type: 'semantic_text', + text: { + type: 'text', metadata_field: false, - searchable: false, + searchable: true, aggregatable: false, }, }, @@ -127,10 +127,10 @@ export const DENSE_SEMANTIC_FIELD_FIELD_CAPS = { indices: ['test-index2'], fields: { infer_field: { - semantic_text: { - type: 'semantic_text', + text: { + type: 'text', metadata_field: false, - searchable: false, + searchable: true, aggregatable: false, }, }, diff --git a/x-pack/solutions/search/plugins/search_playground/server/lib/fetch_query_source_fields.ts b/x-pack/solutions/search/plugins/search_playground/server/lib/fetch_query_source_fields.ts index 9592766e115ec..154261a019528 100644 --- a/x-pack/solutions/search/plugins/search_playground/server/lib/fetch_query_source_fields.ts +++ b/x-pack/solutions/search/plugins/search_playground/server/lib/fetch_query_source_fields.ts @@ -244,10 +244,9 @@ export const parseFieldsCapabilities = ( (indexModelIdField) => indexModelIdField.index === index )!; const nestedField = isFieldNested(fieldKey, fieldCapsResponse); + const semanticFieldMapping = getSemanticField(fieldKey, semanticTextFields); - if (isFieldInIndex(field, 'semantic_text', index)) { - const semanticFieldMapping = getSemanticField(fieldKey, semanticTextFields); - + if (isFieldInIndex(field, 'text', index) && semanticFieldMapping) { // only use this when embeddingType and inferenceId is defined // this requires semantic_text field to be set up correctly and ingested if ( @@ -260,7 +259,7 @@ export const parseFieldsCapabilities = ( field: fieldKey, inferenceId: semanticFieldMapping.inferenceId, embeddingType: semanticFieldMapping.embeddingType, - indices: (field.semantic_text.indices as string[]) || indicesPresentIn, + indices: (field.text.indices as string[]) || indicesPresentIn, }; acc[index].semantic_fields.push(semanticField); diff --git a/x-pack/solutions/search/plugins/search_playground/server/utils/stream_factory.ts b/x-pack/solutions/search/plugins/search_playground/server/utils/stream_factory.ts index 529b913293021..c21d9cc005fa3 100644 --- a/x-pack/solutions/search/plugins/search_playground/server/utils/stream_factory.ts +++ b/x-pack/solutions/search/plugins/search_playground/server/utils/stream_factory.ts @@ -107,7 +107,7 @@ export function streamFactory(logger: Logger, isCloud: boolean = false): StreamF ); if (line === undefined) { - logger.error('Stream chunk must not be undefined.'); + logDebugMessage('Stream chunk must not be undefined.'); return; }