diff --git a/x-pack/solutions/observability/plugins/synthetics/common/requests/get_certs_request_body.ts b/x-pack/solutions/observability/plugins/synthetics/common/requests/get_certs_request_body.ts index af68caac2d413..79f6d88384404 100644 --- a/x-pack/solutions/observability/plugins/synthetics/common/requests/get_certs_request_body.ts +++ b/x-pack/solutions/observability/plugins/synthetics/common/requests/get_certs_request_body.ts @@ -7,7 +7,11 @@ import type { estypes } from '@elastic/elasticsearch'; import DateMath from '@kbn/datemath'; -import { EXCLUDE_RUN_ONCE_FILTER, FINAL_SUMMARY_FILTER } from '../constants/client_defaults'; +import { + EXCLUDE_RUN_ONCE_FILTER, + FINAL_SUMMARY_FILTER, + getRangeFilter, +} from '../constants/client_defaults'; import type { CertificatesResults } from '../../server/queries/get_certs'; import { CertResult, GetCertsParams, Ping } from '../runtime_types'; import { createEsQuery } from '../utils/es_search'; @@ -46,7 +50,7 @@ export const getCertsRequestBody = ({ }: GetCertsParams) => { const sort = SortFields[sortBy as keyof typeof SortFields]; - const searchRequest = createEsQuery({ + return createEsQuery({ from: (pageIndex ?? 0) * size, size, sort: asMutableArray([ @@ -88,6 +92,11 @@ export const getCertsRequestBody = ({ field: 'tls.server.hash.sha256', }, }, + // fetch large enough date range to cover the last 7 days, no particular reason for 7 days + getRangeFilter({ + from: 'now-7d', + to: 'now', + }), { range: { 'monitor.timespan': { @@ -172,8 +181,6 @@ export const getCertsRequestBody = ({ }, }, }); - - return searchRequest; }; export const processCertsResult = (result: CertificatesResults): CertResult => { diff --git a/x-pack/solutions/observability/plugins/uptime/common/constants/client_defaults.ts b/x-pack/solutions/observability/plugins/uptime/common/constants/client_defaults.ts index f627180991025..30d68c2f81307 100644 --- a/x-pack/solutions/observability/plugins/uptime/common/constants/client_defaults.ts +++ b/x-pack/solutions/observability/plugins/uptime/common/constants/client_defaults.ts @@ -81,3 +81,12 @@ export const getTimeSpanFilter = () => ({ }, }, }); + +export const getRangeFilter = ({ from, to }: { from: string; to: string }) => ({ + range: { + '@timestamp': { + gte: from, + lte: to, + }, + }, +}); diff --git a/x-pack/solutions/observability/plugins/uptime/common/requests/get_certs_request_body.ts b/x-pack/solutions/observability/plugins/uptime/common/requests/get_certs_request_body.ts index a72e391f104bb..52f3ff0f3446c 100644 --- a/x-pack/solutions/observability/plugins/uptime/common/requests/get_certs_request_body.ts +++ b/x-pack/solutions/observability/plugins/uptime/common/requests/get_certs_request_body.ts @@ -7,7 +7,11 @@ import type { estypes } from '@elastic/elasticsearch'; import DateMath from '@kbn/datemath'; -import { EXCLUDE_RUN_ONCE_FILTER, SUMMARY_FILTER } from '../constants/client_defaults'; +import { + EXCLUDE_RUN_ONCE_FILTER, + SUMMARY_FILTER, + getRangeFilter, +} from '../constants/client_defaults'; import { CertResult, GetCertsParams, Ping } from '../runtime_types'; import { createEsQuery } from '../utils/es_search'; @@ -88,6 +92,10 @@ export const getCertsRequestBody = ({ field: 'tls.server.hash.sha256', }, }, + getRangeFilter({ + from: 'now-7d', + to: 'now', + }), { range: { 'monitor.timespan': { diff --git a/x-pack/solutions/observability/plugins/uptime/server/legacy_uptime/lib/requests/get_certs.test.ts b/x-pack/solutions/observability/plugins/uptime/server/legacy_uptime/lib/requests/get_certs.test.ts index 7c6aa1fed6be3..460acd930017c 100644 --- a/x-pack/solutions/observability/plugins/uptime/server/legacy_uptime/lib/requests/get_certs.test.ts +++ b/x-pack/solutions/observability/plugins/uptime/server/legacy_uptime/lib/requests/get_certs.test.ts @@ -203,6 +203,14 @@ describe('getCerts', () => { "field": "tls.server.hash.sha256", }, }, + Object { + "range": Object { + "@timestamp": Object { + "gte": "now-7d", + "lte": "now", + }, + }, + }, Object { "range": Object { "monitor.timespan": Object {