diff --git a/x-pack/plugins/search_playground/server/utils/get_value_for_selected_field.test.ts b/x-pack/plugins/search_playground/server/utils/get_value_for_selected_field.test.ts index cfdefc99f80ef..7eae929cc70c0 100644 --- a/x-pack/plugins/search_playground/server/utils/get_value_for_selected_field.test.ts +++ b/x-pack/plugins/search_playground/server/utils/get_value_for_selected_field.test.ts @@ -123,4 +123,17 @@ describe('getValueForSelectedField', () => { seeking consolation and, eventually, redemption through basic compassion" `); }); + + test('should return when path is semantic field', () => { + const hit = { + _index: 'sample-index', + _id: '8jSNY48B6iHEi98DL1C-', + _score: 0.7789394, + _source: { + test: { text: 'The Shawshank Redemption' }, + }, + }; + + expect(getValueForSelectedField(hit, 'test')).toEqual('The Shawshank Redemption'); + }); }); diff --git a/x-pack/plugins/search_playground/server/utils/get_value_for_selected_field.ts b/x-pack/plugins/search_playground/server/utils/get_value_for_selected_field.ts index 695c56a571374..5556e407de979 100644 --- a/x-pack/plugins/search_playground/server/utils/get_value_for_selected_field.ts +++ b/x-pack/plugins/search_playground/server/utils/get_value_for_selected_field.ts @@ -6,7 +6,7 @@ */ import { SearchHit } from '@elastic/elasticsearch/lib/api/types'; -import { get } from 'lodash'; +import { get, has } from 'lodash'; export const getValueForSelectedField = (hit: SearchHit, path: string): string => { if (!hit) { @@ -21,5 +21,7 @@ export const getValueForSelectedField = (hit: SearchHit, path: string): string = .join('\n --- \n'); } - return get(hit._source, path, ''); + return has(hit._source, `${path}.text`) + ? get(hit._source, `${path}.text`, '') + : get(hit._source, path, ''); };