Skip to content

Commit 6321ff1

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 f1ee208 commit 6321ff1

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
]
@@ -249,9 +253,9 @@ Ordering the buckets by their `doc_count` in an ascending manner:
249253
--------------------------------------------------
250254
{
251255
"aggs" : {
252-
"genders" : {
256+
"genres" : {
253257
"terms" : {
254-
"field" : "gender",
258+
"field" : "genre",
255259
"order" : { "_count" : "asc" }
256260
}
257261
}
@@ -265,9 +269,9 @@ Ordering the buckets alphabetically by their terms in an ascending manner:
265269
--------------------------------------------------
266270
{
267271
"aggs" : {
268-
"genders" : {
272+
"genres" : {
269273
"terms" : {
270-
"field" : "gender",
274+
"field" : "genre",
271275
"order" : { "_term" : "asc" }
272276
}
273277
}
@@ -282,13 +286,13 @@ Ordering the buckets by single value metrics sub-aggregation (identified by the
282286
--------------------------------------------------
283287
{
284288
"aggs" : {
285-
"genders" : {
289+
"genres" : {
286290
"terms" : {
287-
"field" : "gender",
288-
"order" : { "avg_height" : "desc" }
291+
"field" : "genre",
292+
"order" : { "avg_play_count" : "desc" }
289293
},
290294
"aggs" : {
291-
"avg_height" : { "avg" : { "field" : "height" } }
295+
"avg_play_count" : { "avg" : { "field" : "play_count" } }
292296
}
293297
}
294298
}
@@ -301,13 +305,13 @@ Ordering the buckets by multi value metrics sub-aggregation (identified by the a
301305
--------------------------------------------------
302306
{
303307
"aggs" : {
304-
"genders" : {
308+
"genres" : {
305309
"terms" : {
306-
"field" : "gender",
307-
"order" : { "height_stats.avg" : "desc" }
310+
"field" : "genre",
311+
"order" : { "playback_stats.avg" : "desc" }
308312
},
309313
"aggs" : {
310-
"height_stats" : { "stats" : { "field" : "height" } }
314+
"playback_stats" : { "stats" : { "field" : "play_count" } }
311315
}
312316
}
313317
}
@@ -345,14 +349,14 @@ PATH := <AGG_NAME>[<AGG_SEPARATOR><AGG_NAME>]*[<METRIC_SEPARATOR
345349
"aggs" : {
346350
"countries" : {
347351
"terms" : {
348-
"field" : "address.country",
349-
"order" : { "females>height_stats.avg" : "desc" }
352+
"field" : "artist.country",
353+
"order" : { "rock>playback_stats.avg" : "desc" }
350354
},
351355
"aggs" : {
352-
"females" : {
353-
"filter" : { "term" : { "gender" : "female" }},
356+
"rock" : {
357+
"filter" : { "term" : { "genre" : "rock" }},
354358
"aggs" : {
355-
"height_stats" : { "stats" : { "field" : "height" }}
359+
"playback_stats" : { "stats" : { "field" : "play_count" }}
356360
}
357361
}
358362
}
@@ -361,7 +365,7 @@ PATH := <AGG_NAME>[<AGG_SEPARATOR><AGG_NAME>]*[<METRIC_SEPARATOR
361365
}
362366
--------------------------------------------------
363367

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

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

@@ -371,14 +375,14 @@ Multiple criteria can be used to order the buckets by providing an array of orde
371375
"aggs" : {
372376
"countries" : {
373377
"terms" : {
374-
"field" : "address.country",
375-
"order" : [ { "females>height_stats.avg" : "desc" }, { "_count" : "desc" } ]
378+
"field" : "artist.country",
379+
"order" : [ { "rock>playback_stats.avg" : "desc" }, { "_count" : "desc" } ]
376380
},
377381
"aggs" : {
378-
"females" : {
379-
"filter" : { "term" : { "gender" : { "female" }}},
382+
"rock" : {
383+
"filter" : { "term" : { "genre" : { "rock" }}},
380384
"aggs" : {
381-
"height_stats" : { "stats" : { "field" : "height" }}
385+
"playback_stats" : { "stats" : { "field" : "play_count" }}
382386
}
383387
}
384388
}
@@ -387,7 +391,7 @@ Multiple criteria can be used to order the buckets by providing an array of orde
387391
}
388392
--------------------------------------------------
389393

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

393397
NOTE: In the event that two buckets share the same values for all order criteria the bucket's term value is used as a
@@ -441,9 +445,9 @@ Generating the terms using a script:
441445
--------------------------------------------------
442446
{
443447
"aggs" : {
444-
"genders" : {
448+
"genres" : {
445449
"terms" : {
446-
"script" : "doc['gender'].value"
450+
"script" : "doc['genre'].value"
447451
}
448452
}
449453
}
@@ -456,12 +460,12 @@ This will interpret the `script` parameter as an `inline` script with the defaul
456460
--------------------------------------------------
457461
{
458462
"aggs" : {
459-
"genders" : {
463+
"genres" : {
460464
"terms" : {
461465
"script" : {
462466
"file": "my_script",
463467
"params": {
464-
"field": "gender"
468+
"field": "genre"
465469
}
466470
}
467471
}
@@ -479,10 +483,10 @@ TIP: for indexed scripts replace the `file` parameter with an `id` parameter.
479483
--------------------------------------------------
480484
{
481485
"aggs" : {
482-
"genders" : {
486+
"genres" : {
483487
"terms" : {
484-
"field" : "gender",
485-
"script" : "'Gender: ' +_value"
488+
"field" : "genre",
489+
"script" : "'Genre: ' +_value"
486490
}
487491
}
488492
}

0 commit comments

Comments
 (0)