Solution 19
GET olympic-events-fixed/_search
{
"size": 0,
"query": {
"term": {
"sport": {
"value": "Gymnastics"
}
}
},
"aggs": {
"event_types": {
"terms": {
"field": "event.keyword",
"size": 100
}
}
}
}
Solution 20
GET olympic-events-fixed/_search
{
"size": 0,
"query": {
"term": {
"sport": {
"value": "Gymnastics"
}
}
},
"aggs": {
"genders": {
"terms": {
"field": "gender"
},
"aggs": {
"avg_weight": {
"avg": {
"field": "weight"
}
}
}
}
}
}
Solution 21
GET olympic-events-fixed/_search
{
"size": 0,
"aggs": {
"events": {
"terms": {
"field": "event.keyword",
"size": 590
},
"aggs": {
"first_year": {
"min": {
"field": "year"
}
}
}
},
"most_recent": {
"max_bucket": {
"buckets_path": "events>first_year"
}
}
}
}
Solution 22
GET olympic-events-fixed/_search
{
"_source": ["athleteName.keyword", "team", "sport", "age", "height", "weight", "gender"],
"query": {
"term": {
"year": {
"value": 2016
}
}
}
}
Solution 23
GET olympic-events-fixed/_search
{
"_source": ["athleteName.keyword", "team", "sport", "age", "height", "weight", "gender"],
"script_fields": {
"weightLbs": {
"script": {
"lang": "painless",
"source": "doc['weight'].value * 2.2"
}
}
},
"query": {
"term": {
"year": {
"value": 2016
}
}
}
}
Solution 24
GET olympic-events-fixed/_search
{
"_source": ["athleteName.keyword", "team", "sport", "age", "height", "weight", "gender"],
"script_fields": {
"weightLbs": {
"script": {
"lang": "painless",
"source": "doc['weight'].value * 2.2"
}
},
"bmi": {
"script": {
"lang": "painless",
"source": "doc['weight'].value / (Math.pow(doc['height'].value / 100.0f, 2))"
}
}
},
"query": {
"term": {
"year": {
"value": 2016
}
}
}
}
Next steps
The solutions to the next set of exercises can be found here.