[Backport 8.x] Add _id to the result of helpers.search (#2434)

(cherry picked from commit 2455dac4e5)

Co-authored-by: Rami <72725910+ramikg@users.noreply.github.com>
This commit is contained in:
github-actions[bot]
2024-11-06 12:27:50 -06:00
committed by GitHub
parent dd9b38b051
commit a829634f83
2 changed files with 25 additions and 18 deletions

View File

@ -24,14 +24,14 @@ import { connection } from '../../utils'
test('Search should have an additional documents property', async t => {
const MockConnection = connection.buildMockConnection({
onRequest (params) {
t.equal(params.querystring, 'filter_path=hits.hits._source')
t.equal(params.querystring, 'filter_path=hits.hits._id%2Chits.hits._source')
return {
body: {
hits: {
hits: [
{ _source: { one: 'one' } },
{ _source: { two: 'two' } },
{ _source: { three: 'three' } }
{ _id: '1', _source: { one: 'one' } },
{ _id: '2', _source: { two: 'two' } },
{ _id: '3', _source: { three: 'three' } }
]
}
}
@ -49,16 +49,16 @@ test('Search should have an additional documents property', async t => {
query: { match_all: {} }
})
t.same(result, [
{ one: 'one' },
{ two: 'two' },
{ three: 'three' }
{ _id: '1', one: 'one' },
{ _id: '2', two: 'two' },
{ _id: '3', three: 'three' }
])
})
test('kGetHits fallback', async t => {
const MockConnection = connection.buildMockConnection({
onRequest (params) {
t.equal(params.querystring, 'filter_path=hits.hits._source')
t.equal(params.querystring, 'filter_path=hits.hits._id%2Chits.hits._source')
return { body: {} }
}
})
@ -78,14 +78,14 @@ test('kGetHits fallback', async t => {
test('Merge filter paths (snake_case)', async t => {
const MockConnection = connection.buildMockConnection({
onRequest (params) {
t.equal(params.querystring, 'filter_path=foo%2Chits.hits._source')
t.equal(params.querystring, 'filter_path=foo%2Chits.hits._id%2Chits.hits._source')
return {
body: {
hits: {
hits: [
{ _source: { one: 'one' } },
{ _source: { two: 'two' } },
{ _source: { three: 'three' } }
{ _id: '1', _source: { one: 'one' } },
{ _id: '2', _source: { two: 'two' } },
{ _id: '3', _source: { three: 'three' } }
]
}
}
@ -104,9 +104,9 @@ test('Merge filter paths (snake_case)', async t => {
query: { match_all: {} }
})
t.same(result, [
{ one: 'one' },
{ two: 'two' },
{ three: 'three' }
{ _id: '1', one: 'one' },
{ _id: '2', two: 'two' },
{ _id: '3', three: 'three' }
])
})