Skip to content

Commit f3402f4

Browse files
[8.x] [Search] [Playground] Bug get text field for semantic field (#197345) (#197814)
# Backport This will backport the following commits from `main` to `8.x`: - [[Search] [Playground] Bug get text field for semantic field (#197345)](#197345) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Yan Savitski","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-25T11:54:16Z","message":"[Search] [Playground] Bug get text field for semantic field (#197345)\n\n- Fix [Object object] in retrieval documents when semantic text is used\r\n<img width=\"825\" alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/39b154ac-727b-40c2-8262-4ff6f892a634\">","sha":"a224f9e14bcfc94db669c7e73dc97fc923326e36","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Search","backport:prev-minor","v8.16.0"],"title":"[Search] [Playground] Bug get text field for semantic field","number":197345,"url":"https://github.com/elastic/kibana/pull/197345","mergeCommit":{"message":"[Search] [Playground] Bug get text field for semantic field (#197345)\n\n- Fix [Object object] in retrieval documents when semantic text is used\r\n<img width=\"825\" alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/39b154ac-727b-40c2-8262-4ff6f892a634\">","sha":"a224f9e14bcfc94db669c7e73dc97fc923326e36"}},"sourceBranch":"main","suggestedTargetBranches":["8.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/197345","number":197345,"mergeCommit":{"message":"[Search] [Playground] Bug get text field for semantic field (#197345)\n\n- Fix [Object object] in retrieval documents when semantic text is used\r\n<img width=\"825\" alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/39b154ac-727b-40c2-8262-4ff6f892a634\">","sha":"a224f9e14bcfc94db669c7e73dc97fc923326e36"}},{"branch":"8.16","label":"v8.16.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Yan Savitski <[email protected]>
1 parent aa26956 commit f3402f4

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

x-pack/plugins/search_playground/server/utils/get_value_for_selected_field.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,17 @@ describe('getValueForSelectedField', () => {
123123
seeking consolation and, eventually, redemption through basic compassion"
124124
`);
125125
});
126+
127+
test('should return when path is semantic field', () => {
128+
const hit = {
129+
_index: 'sample-index',
130+
_id: '8jSNY48B6iHEi98DL1C-',
131+
_score: 0.7789394,
132+
_source: {
133+
test: { text: 'The Shawshank Redemption' },
134+
},
135+
};
136+
137+
expect(getValueForSelectedField(hit, 'test')).toEqual('The Shawshank Redemption');
138+
});
126139
});

x-pack/plugins/search_playground/server/utils/get_value_for_selected_field.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { SearchHit } from '@elastic/elasticsearch/lib/api/types';
9-
import { get } from 'lodash';
9+
import { get, has } from 'lodash';
1010

1111
export const getValueForSelectedField = (hit: SearchHit, path: string): string => {
1212
if (!hit) {
@@ -21,5 +21,7 @@ export const getValueForSelectedField = (hit: SearchHit, path: string): string =
2121
.join('\n --- \n');
2222
}
2323

24-
return get(hit._source, path, '');
24+
return has(hit._source, `${path}.text`)
25+
? get(hit._source, `${path}.text`, '')
26+
: get(hit._source, path, '');
2527
};

0 commit comments

Comments
 (0)