Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have FTR tests that demonstrate this issue is fixed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve added a unit test. Adding an FTR test would require significant changes in ftr, like creating an index with a semantic field and relevant data. Considering the simplicity of the case, maybe unit test would be enough?

? get(hit._source, `${path}.text`, '')
: get(hit._source, path, '');
};