Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] Use unmapped_type: long and missing: 0 when sorting datasets that don't include event.ingested #136114

Merged
merged 10 commits into from
Jul 14, 2022
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/cypress/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"baseUrl": "http://localhost:5620",
"defaultCommandTimeout": 60000,
"requestTimeout": 60000,
"responseTimetout": 60000,
"responseTimeout": 60000,
"execTimeout": 120000,
"pageLoadTimeout": 120000,
"nodeVersion": "system",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,22 @@ export async function getDataStreamsQueryMetadata({
esClient.search({
size: 1,
index: dataStreamName,
sort: 'event.ingested:desc',
_source: false,
fields: ['event.ingested'],
// We need to use `body` to control the `sort` value here, because otherwise
// it's just appended as a query string to the search operation and we can't
// set `unmapped_type` for cases where `event.ingested` is not defiend, e.g.
// in custom logs or custom HTTPJSON integrations
body: {
sort: {
'event.ingested': {
order: 'desc',
// Necessary because of https://github.com/elastic/elasticsearch/issues/81960
missing: 0,
unmapped_type: 'long',
},
},
},
}),
esClient.termsEnum({
index: dataStreamName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export const getListHandler: RequestHandler = async (context, request, response)
});

// Return final data streams objects sorted by last activity, descending
// After filtering out data streams that are missing dataset/namespace/type fields
// After filtering out data streams that are missing dataset/namespace/type/package fields
body.data_streams = (await Promise.all(dataStreamPromises))
.filter(({ dataset, namespace, type }) => dataset && namespace && type)
.sort((a, b) => b.last_activity_ms - a.last_activity_ms);
Expand Down