[Backport 7.x] Use filter_path for improving the search helpers performances (#1201)

This commit is contained in:
github-actions[bot]
2020-05-25 14:26:58 +02:00
committed by GitHub
parent 8a1e9576aa
commit 35e587663c
4 changed files with 105 additions and 10 deletions

View File

@ -11,6 +11,7 @@ const { connection } = require('../../utils')
test('Search should have an additional documents property', async t => {
const MockConnection = connection.buildMockConnection({
onRequest (params) {
t.strictEqual(params.querystring, 'filter_path=hits.hits._source')
return {
body: {
hits: {
@ -44,6 +45,7 @@ test('Search should have an additional documents property', async t => {
test('kGetHits fallback', async t => {
const MockConnection = connection.buildMockConnection({
onRequest (params) {
t.strictEqual(params.querystring, 'filter_path=hits.hits._source')
return { body: {} }
}
})
@ -59,3 +61,73 @@ test('kGetHits fallback', async t => {
})
t.deepEqual(result, [])
})
test('Merge filter paths (snake_case)', async t => {
const MockConnection = connection.buildMockConnection({
onRequest (params) {
t.strictEqual(params.querystring, 'filter_path=foo%2Chits.hits._source')
return {
body: {
hits: {
hits: [
{ _source: { one: 'one' } },
{ _source: { two: 'two' } },
{ _source: { three: 'three' } }
]
}
}
}
}
})
const client = new Client({
node: 'http://localhost:9200',
Connection: MockConnection
})
const result = await client.helpers.search({
index: 'test',
filter_path: 'foo',
body: { foo: 'bar' }
})
t.deepEqual(result, [
{ one: 'one' },
{ two: 'two' },
{ three: 'three' }
])
})
test('Merge filter paths (camelCase)', async t => {
const MockConnection = connection.buildMockConnection({
onRequest (params) {
t.strictEqual(params.querystring, 'filter_path=foo%2Chits.hits._source')
return {
body: {
hits: {
hits: [
{ _source: { one: 'one' } },
{ _source: { two: 'two' } },
{ _source: { three: 'three' } }
]
}
}
}
}
})
const client = new Client({
node: 'http://localhost:9200',
Connection: MockConnection
})
const result = await client.helpers.search({
index: 'test',
filterPath: 'foo',
body: { foo: 'bar' }
})
t.deepEqual(result, [
{ one: 'one' },
{ two: 'two' },
{ three: 'three' }
])
})