[8.x] [eem] use `values` for metadata aggs (#204460) (#204530)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[eem] use `values` for metadata aggs
(#204460)](https://github.com/elastic/kibana/pull/204460)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Kevin
Lacabane","email":"kevin.lacabane@elastic.co"},"sourceCommit":{"committedDate":"2024-12-17T09:57:51Z","message":"[eem]
use `values` for metadata aggs (#204460)\n\nwe need unique
values","sha":"4eaceb26588215032345904a37fe5b6654e84c9c","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","Team:obs-entities"],"title":"[eem]
use `values` for metadata
aggs","number":204460,"url":"https://github.com/elastic/kibana/pull/204460","mergeCommit":{"message":"[eem]
use `values` for metadata aggs (#204460)\n\nwe need unique
values","sha":"4eaceb26588215032345904a37fe5b6654e84c9c"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/204460","number":204460,"mergeCommit":{"message":"[eem]
use `values` for metadata aggs (#204460)\n\nwe need unique
values","sha":"4eaceb26588215032345904a37fe5b6654e84c9c"}}]}]
BACKPORT-->

Co-authored-by: Kevin Lacabane <kevin.lacabane@elastic.co>
This commit is contained in:
Kibana Machine 2024-12-17 22:46:54 +11:00 committed by GitHub
parent ab308aa2d0
commit 1b82c6d8ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View file

@ -28,7 +28,7 @@ describe('getEntityInstancesQuery', () => {
expect(query).toEqual(
'FROM logs-*, metrics-* | ' +
'STATS host.name = TOP(host.name::keyword, 10, "ASC"), entity.last_seen_timestamp = MAX(custom_timestamp_field), service.id = MAX(service.id::keyword) BY service.name::keyword | ' +
'STATS host.name = VALUES(host.name::keyword), entity.last_seen_timestamp = MAX(custom_timestamp_field), service.id = MAX(service.id::keyword) BY service.name::keyword | ' +
'RENAME `service.name::keyword` AS service.name | ' +
'EVAL entity.type = "service", entity.id = service.name, entity.display_name = COALESCE(service.id, entity.id) | ' +
'SORT entity.id DESC | ' +

View file

@ -46,7 +46,7 @@ const dslFilter = ({
const statsCommand = ({ source }: { source: EntitySourceDefinition }) => {
const aggs = source.metadata_fields
.filter((field) => !source.identity_fields.some((idField) => idField === field))
.map((field) => `${field} = TOP(${asKeyword(field)}, 10, "ASC")`);
.map((field) => `${field} = VALUES(${asKeyword(field)})`);
if (source.timestamp_field) {
aggs.push(`entity.last_seen_timestamp = MAX(${source.timestamp_field})`);