-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '7.7' into backport/7.7/pr-61641
- Loading branch information
Showing
7 changed files
with
94 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
x-pack/plugins/data_enhanced/server/search/shim_hits_total.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { shimHitsTotal } from './shim_hits_total'; | ||
|
||
describe('shimHitsTotal', () => { | ||
test('returns the total if it is already numeric', () => { | ||
const result = shimHitsTotal({ | ||
hits: { | ||
total: 5, | ||
}, | ||
} as any); | ||
expect(result).toEqual({ | ||
hits: { | ||
total: 5, | ||
}, | ||
}); | ||
}); | ||
|
||
test('returns the total if it is inside `value`', () => { | ||
const result = shimHitsTotal({ | ||
hits: { | ||
total: { | ||
value: 5, | ||
}, | ||
}, | ||
} as any); | ||
expect(result).toEqual({ | ||
hits: { | ||
total: 5, | ||
}, | ||
}); | ||
}); | ||
|
||
test('returns other properties from the response', () => { | ||
const result = shimHitsTotal({ | ||
_shards: {}, | ||
hits: { | ||
hits: [], | ||
total: { | ||
value: 5, | ||
}, | ||
}, | ||
} as any); | ||
expect(result).toEqual({ | ||
_shards: {}, | ||
hits: { | ||
hits: [], | ||
total: 5, | ||
}, | ||
}); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
x-pack/plugins/data_enhanced/server/search/shim_hits_total.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { SearchResponse } from 'elasticsearch'; | ||
|
||
/** | ||
* Temporary workaround until https://github.com/elastic/kibana/issues/26356 is addressed. | ||
* Since we are setting `track_total_hits` in the request, `hits.total` will be an object | ||
* containing the `value`. | ||
*/ | ||
export function shimHitsTotal(response: SearchResponse<any>) { | ||
const total = (response.hits?.total as any)?.value ?? response.hits?.total; | ||
const hits = { ...response.hits, total }; | ||
return { ...response, hits }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters