Skip to content

Commit c7eeb9d

Browse files
authored
[DOCS] Adds missing parameter to the top metrics agg docs (#96297) (#96860)
1 parent 7a1b88e commit c7eeb9d

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

docs/reference/aggregations/metrics/top-metrics-aggregation.asciidoc

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,78 @@ Which returns:
142142
----
143143
// TESTRESPONSE
144144

145+
146+
==== `missing`
147+
148+
The `missing` parameter defines how documents with a missing value are treated.
149+
By default, if any of the key components are missing, the entire document is
150+
ignored. It is possible to treat the missing components as if they had a value
151+
by using the `missing` parameter.
152+
153+
[source,console]
154+
----
155+
PUT /my-index
156+
{
157+
"mappings": {
158+
"properties": {
159+
"nr": { "type": "integer" },
160+
"state": { "type": "keyword" } <1>
161+
}
162+
}
163+
}
164+
POST /my-index/_bulk?refresh
165+
{"index": {}}
166+
{"nr": 1, "state": "started"}
167+
{"index": {}}
168+
{"nr": 2, "state": "stopped"}
169+
{"index": {}}
170+
{"nr": 3, "state": "N/A"}
171+
{"index": {}}
172+
{"nr": 4} <2>
173+
POST /my-index/_search?filter_path=aggregations
174+
{
175+
"aggs": {
176+
"my_top_metrics": {
177+
"top_metrics": {
178+
"metrics": {
179+
"field": "state",
180+
"missing": "N/A"}, <3>
181+
"sort": {"nr": "desc"}
182+
}
183+
}
184+
}
185+
}
186+
----
187+
188+
<1> If you want to use an aggregation on textual content, it must be a `keyword`
189+
type field or you must enable fielddata on that field.
190+
<2> This document has a missing `state` field value.
191+
<3> The `missing` parameter defines that if `state` field has a missing value,
192+
it should be treated as if it had the `N/A` value.
193+
194+
The request results in the following response:
195+
196+
[source,console-result]
197+
----
198+
{
199+
"aggregations": {
200+
"my_top_metrics": {
201+
"top": [
202+
{
203+
"sort": [
204+
4
205+
],
206+
"metrics": {
207+
"state": "N/A"
208+
}
209+
}
210+
]
211+
}
212+
}
213+
}
214+
----
215+
216+
145217
==== `size`
146218

147219
`top_metrics` can return the top few document's worth of metrics using the size parameter:

0 commit comments

Comments
 (0)