diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/top_metrics.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/top_metrics.yml index 2fa64ee894e4e..a5ee9f7be8ee0 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/top_metrics.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/analytics/top_metrics.yml @@ -708,3 +708,42 @@ - match: { aggregations.tm.top.1.sort: [2] } - match: { aggregations.tm.top.2.metrics.animal\.keyword: null} - match: { aggregations.tm.top.2.sort: [3] } + +--- +"with flattened": + - do: + indices.create: + index: test + body: + mappings: + properties: + host: + type: flattened + + - do: + bulk: + index: test + refresh: true + body: + - '{"index": {}}' + - '{"host": {"hostname": "abc", "name": "x"}, "v": 1}' + - '{"index": {}}' + - '{"host": {"hostname": "foo", "name": "y"}, "v": 2}' + - '{"index": {}}' + - '{"host": {"hostname": "bar", "name": "z"}, "v": 3}' + + - do: + search: + index: test + size: 0 + body: + aggs: + tm: + top_metrics: + metrics: + field: host.hostname + sort: + v: asc + size: 3 + - match: { aggregations.tm.top.0.sort: [1] } + - match: { aggregations.tm.top.0.metrics.host\.hostname: abc }