9
9
--------------------------------------------------
10
10
{
11
11
"aggs" : {
12
- "genders " : {
13
- "terms" : { "field" : "gender " }
12
+ "genres " : {
13
+ "terms" : { "field" : "genre " }
14
14
}
15
15
}
16
16
}
@@ -24,16 +24,20 @@ Response:
24
24
...
25
25
26
26
"aggregations" : {
27
- "genders " : {
27
+ "genres " : {
28
28
"doc_count_error_upper_bound": 0, <1>
29
29
"sum_other_doc_count": 0, <2>
30
30
"buckets" : [ <3>
31
31
{
32
- "key" : "male ",
32
+ "key" : "jazz ",
33
33
"doc_count" : 10
34
34
},
35
35
{
36
- "key" : "female",
36
+ "key" : "rock",
37
+ "doc_count" : 10
38
+ },
39
+ {
40
+ "key" : "electronic",
37
41
"doc_count" : 10
38
42
},
39
43
]
@@ -249,9 +253,9 @@ Ordering the buckets by their `doc_count` in an ascending manner:
249
253
--------------------------------------------------
250
254
{
251
255
"aggs" : {
252
- "genders " : {
256
+ "genres " : {
253
257
"terms" : {
254
- "field" : "gender ",
258
+ "field" : "genre ",
255
259
"order" : { "_count" : "asc" }
256
260
}
257
261
}
@@ -265,9 +269,9 @@ Ordering the buckets alphabetically by their terms in an ascending manner:
265
269
--------------------------------------------------
266
270
{
267
271
"aggs" : {
268
- "genders " : {
272
+ "genres " : {
269
273
"terms" : {
270
- "field" : "gender ",
274
+ "field" : "genre ",
271
275
"order" : { "_term" : "asc" }
272
276
}
273
277
}
@@ -282,13 +286,13 @@ Ordering the buckets by single value metrics sub-aggregation (identified by the
282
286
--------------------------------------------------
283
287
{
284
288
"aggs" : {
285
- "genders " : {
289
+ "genres " : {
286
290
"terms" : {
287
- "field" : "gender ",
288
- "order" : { "avg_height " : "desc" }
291
+ "field" : "genre ",
292
+ "order" : { "avg_play_count " : "desc" }
289
293
},
290
294
"aggs" : {
291
- "avg_height " : { "avg" : { "field" : "height " } }
295
+ "avg_play_count " : { "avg" : { "field" : "play_count " } }
292
296
}
293
297
}
294
298
}
@@ -301,13 +305,13 @@ Ordering the buckets by multi value metrics sub-aggregation (identified by the a
301
305
--------------------------------------------------
302
306
{
303
307
"aggs" : {
304
- "genders " : {
308
+ "genres " : {
305
309
"terms" : {
306
- "field" : "gender ",
307
- "order" : { "height_stats .avg" : "desc" }
310
+ "field" : "genre ",
311
+ "order" : { "playback_stats .avg" : "desc" }
308
312
},
309
313
"aggs" : {
310
- "height_stats " : { "stats" : { "field" : "height " } }
314
+ "playback_stats " : { "stats" : { "field" : "play_count " } }
311
315
}
312
316
}
313
317
}
@@ -345,14 +349,14 @@ PATH := <AGG_NAME>[<AGG_SEPARATOR><AGG_NAME>]*[<METRIC_SEPARATOR
345
349
"aggs" : {
346
350
"countries" : {
347
351
"terms" : {
348
- "field" : "address .country",
349
- "order" : { "females>height_stats .avg" : "desc" }
352
+ "field" : "artist .country",
353
+ "order" : { "rock>playback_stats .avg" : "desc" }
350
354
},
351
355
"aggs" : {
352
- "females " : {
353
- "filter" : { "term" : { "gender " : "female " }},
356
+ "rock " : {
357
+ "filter" : { "term" : { "genre " : "rock " }},
354
358
"aggs" : {
355
- "height_stats " : { "stats" : { "field" : "height " }}
359
+ "playback_stats " : { "stats" : { "field" : "play_count " }}
356
360
}
357
361
}
358
362
}
@@ -361,7 +365,7 @@ PATH := <AGG_NAME>[<AGG_SEPARATOR><AGG_NAME>]*[<METRIC_SEPARATOR
361
365
}
362
366
--------------------------------------------------
363
367
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 .
365
369
366
370
Multiple criteria can be used to order the buckets by providing an array of order criteria such as the following:
367
371
@@ -371,14 +375,14 @@ Multiple criteria can be used to order the buckets by providing an array of orde
371
375
"aggs" : {
372
376
"countries" : {
373
377
"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" } ]
376
380
},
377
381
"aggs" : {
378
- "females " : {
379
- "filter" : { "term" : { "gender " : { "female " }}},
382
+ "rock " : {
383
+ "filter" : { "term" : { "genre " : { "rock " }}},
380
384
"aggs" : {
381
- "height_stats " : { "stats" : { "field" : "height " }}
385
+ "playback_stats " : { "stats" : { "field" : "play_count " }}
382
386
}
383
387
}
384
388
}
@@ -387,7 +391,7 @@ Multiple criteria can be used to order the buckets by providing an array of orde
387
391
}
388
392
--------------------------------------------------
389
393
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
391
395
their `doc_count` in descending order.
392
396
393
397
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:
441
445
--------------------------------------------------
442
446
{
443
447
"aggs" : {
444
- "genders " : {
448
+ "genres " : {
445
449
"terms" : {
446
- "script" : "doc['gender '].value"
450
+ "script" : "doc['genre '].value"
447
451
}
448
452
}
449
453
}
@@ -456,12 +460,12 @@ This will interpret the `script` parameter as an `inline` script with the defaul
456
460
--------------------------------------------------
457
461
{
458
462
"aggs" : {
459
- "genders " : {
463
+ "genres " : {
460
464
"terms" : {
461
465
"script" : {
462
466
"file": "my_script",
463
467
"params": {
464
- "field": "gender "
468
+ "field": "genre "
465
469
}
466
470
}
467
471
}
@@ -479,10 +483,10 @@ TIP: for indexed scripts replace the `file` parameter with an `id` parameter.
479
483
--------------------------------------------------
480
484
{
481
485
"aggs" : {
482
- "genders " : {
486
+ "genres " : {
483
487
"terms" : {
484
- "field" : "gender ",
485
- "script" : "'Gender : ' +_value"
488
+ "field" : "genre ",
489
+ "script" : "'Genre : ' +_value"
486
490
}
487
491
}
488
492
}
0 commit comments