Add _id to the result of helpers.search (#2432)

This commit is contained in:
Rami
2024-11-06 20:20:10 +02:00
committed by GitHub
parent edb5563bf8
commit 2455dac4e5
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' }
])
})