Skip to content

Commit 1297a70

Browse files
Leon Weidauerclintongormley
Leon Weidauer
authored andcommitted
non-binary gender option in term aggr. example (#19188)
* non-binary gender option in term aggr. example * replace gender with music genre for term aggregation docs
1 parent 4d67b1f commit 1297a70

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed

docs/reference/aggregations/bucket/terms-aggregation.asciidoc

+40-36
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Example:
99
--------------------------------------------------
1010
{
1111
"aggs" : {
12-
"genders" : {
13-
"terms" : { "field" : "gender" }
12+
"genres" : {
13+
"terms" : { "field" : "genre" }
1414
}
1515
}
1616
}
@@ -24,16 +24,20 @@ Response:
2424
...
2525
2626
"aggregations" : {
27-
"genders" : {
27+
"genres" : {
2828
"doc_count_error_upper_bound": 0, <1>
2929
"sum_other_doc_count": 0, <2>
3030
"buckets" : [ <3>
3131
{
32-
"key" : "male",
32+
"key" : "jazz",
3333
"doc_count" : 10
3434
},
3535
{
36-
"key" : "female",
36+
"key" : "rock",
37+
"doc_count" : 10
38+
},
39+
{
40+
"key" : "electronic",
3741
"doc_count" : 10
3842
},
3943
]
@@ -247,9 +251,9 @@ Ordering the buckets by their `doc_count` in an ascending manner:
247251
--------------------------------------------------
248252
{
249253
"aggs" : {
250-
"genders" : {
254+
"genres" : {
251255
"terms" : {
252-
"field" : "gender",
256+
"field" : "genre",
253257
"order" : { "_count" : "asc" }
254258
}
255259
}
@@ -263,9 +267,9 @@ Ordering the buckets alphabetically by their terms in an ascending manner:
263267
--------------------------------------------------
264268
{
265269
"aggs" : {
266-
"genders" : {
270+
"genres" : {
267271
"terms" : {
268-
"field" : "gender",
272+
"field" : "genre",
269273
"order" : { "_term" : "asc" }
270274
}
271275
}
@@ -280,13 +284,13 @@ Ordering the buckets by single value metrics sub-aggregation (identified by the
280284
--------------------------------------------------
281285
{
282286
"aggs" : {
283-
"genders" : {
287+
"genres" : {
284288
"terms" : {
285-
"field" : "gender",
286-
"order" : { "avg_height" : "desc" }
289+
"field" : "genre",
290+
"order" : { "avg_play_count" : "desc" }
287291
},
288292
"aggs" : {
289-
"avg_height" : { "avg" : { "field" : "height" } }
293+
"avg_play_count" : { "avg" : { "field" : "play_count" } }
290294
}
291295
}
292296
}
@@ -299,13 +303,13 @@ Ordering the buckets by multi value metrics sub-aggregation (identified by the a
299303
--------------------------------------------------
300304
{
301305
"aggs" : {
302-
"genders" : {
306+
"genres" : {
303307
"terms" : {
304-
"field" : "gender",
305-
"order" : { "height_stats.avg" : "desc" }
308+
"field" : "genre",
309+
"order" : { "playback_stats.avg" : "desc" }
306310
},
307311
"aggs" : {
308-
"height_stats" : { "stats" : { "field" : "height" } }
312+
"playback_stats" : { "stats" : { "field" : "play_count" } }
309313
}
310314
}
311315
}
@@ -343,14 +347,14 @@ PATH := <AGG_NAME>[<AGG_SEPARATOR><AGG_NAME>]*[<METRIC_SEPARATOR
343347
"aggs" : {
344348
"countries" : {
345349
"terms" : {
346-
"field" : "address.country",
347-
"order" : { "females>height_stats.avg" : "desc" }
350+
"field" : "artist.country",
351+
"order" : { "rock>playback_stats.avg" : "desc" }
348352
},
349353
"aggs" : {
350-
"females" : {
351-
"filter" : { "term" : { "gender" : "female" }},
354+
"rock" : {
355+
"filter" : { "term" : { "genre" : "rock" }},
352356
"aggs" : {
353-
"height_stats" : { "stats" : { "field" : "height" }}
357+
"playback_stats" : { "stats" : { "field" : "play_count" }}
354358
}
355359
}
356360
}
@@ -359,7 +363,7 @@ PATH := <AGG_NAME>[<AGG_SEPARATOR><AGG_NAME>]*[<METRIC_SEPARATOR
359363
}
360364
--------------------------------------------------
361365

362-
The above will sort the countries buckets based on the average height among the female population.
366+
The above will sort the artist's countries buckets based on the average play count among the rock songs.
363367

364368
Multiple criteria can be used to order the buckets by providing an array of order criteria such as the following:
365369

@@ -369,14 +373,14 @@ Multiple criteria can be used to order the buckets by providing an array of orde
369373
"aggs" : {
370374
"countries" : {
371375
"terms" : {
372-
"field" : "address.country",
373-
"order" : [ { "females>height_stats.avg" : "desc" }, { "_count" : "desc" } ]
376+
"field" : "artist.country",
377+
"order" : [ { "rock>playback_stats.avg" : "desc" }, { "_count" : "desc" } ]
374378
},
375379
"aggs" : {
376-
"females" : {
377-
"filter" : { "term" : { "gender" : { "female" }}},
380+
"rock" : {
381+
"filter" : { "term" : { "genre" : { "rock" }}},
378382
"aggs" : {
379-
"height_stats" : { "stats" : { "field" : "height" }}
383+
"playback_stats" : { "stats" : { "field" : "play_count" }}
380384
}
381385
}
382386
}
@@ -385,7 +389,7 @@ Multiple criteria can be used to order the buckets by providing an array of orde
385389
}
386390
--------------------------------------------------
387391

388-
The above will sort the countries buckets based on the average height among the female population and then by
392+
The above will sort the artist's countries buckets based on the average play count among the rock songs and then by
389393
their `doc_count` in descending order.
390394

391395
NOTE: In the event that two buckets share the same values for all order criteria the bucket's term value is used as a
@@ -439,10 +443,10 @@ Generating the terms using a script:
439443
--------------------------------------------------
440444
{
441445
"aggs" : {
442-
"genders" : {
446+
"genres" : {
443447
"terms" : {
444448
"script" : {
445-
"inline": "doc['gender'].value"
449+
"inline": "doc['genre'].value"
446450
"lang": "painless"
447451
}
448452
}
@@ -457,12 +461,12 @@ This will interpret the `script` parameter as an `inline` script with the defaul
457461
--------------------------------------------------
458462
{
459463
"aggs" : {
460-
"genders" : {
464+
"genres" : {
461465
"terms" : {
462466
"script" : {
463467
"file": "my_script",
464468
"params": {
465-
"field": "gender"
469+
"field": "genre"
466470
}
467471
}
468472
}
@@ -480,11 +484,11 @@ TIP: for indexed scripts replace the `file` parameter with an `id` parameter.
480484
--------------------------------------------------
481485
{
482486
"aggs" : {
483-
"genders" : {
487+
"genres" : {
484488
"terms" : {
485-
"field" : "gender",
489+
"field" : "gendre",
486490
"script" : {
487-
"inline" : "'Gender: ' +_value"
491+
"inline" : "'Genre: ' +_value"
488492
"lang" : "painless"
489493
}
490494
}

0 commit comments

Comments
 (0)