Aggregation Exercise
Log-in into your ElasticSearch sandbox
Make sure elastic search is running:
sudo service elasticsearch restart
Populate few sample movie data:
curl https://elasticsearch-courseware.icssolutions.ca/examples/data-sets/movies.txt -o movies.txt curl -XPOST 'localhost:9200/_bulk' -H 'content-type: application/json' --data-binary "@movies.txt"
Confirm there are some records to search on:
curl 'localhost:9200/movies/movies/_search?pretty=true'
Let's aggregate on actor name
curl -XPOST 'localhost:9200/movies/movies/_search?pretty=true' \ -H 'content-type:application/json' \ -d ' { "size": 0, "aggs": { "actor_name": { "terms": { "field": "Starring.CastCrewName.keyword" } } } }'
What buckets did you get?
How do I get more than 10 buckets? Check StackOverflow posting!
What is 'sum_other_doc_count' field?
Let's find out average movie rating for the actor:
curl -XPOST 'localhost:9200/movies/movies/_search?pretty=true' \ -H 'content-type:application/json' \ -d ' { "size": 0, "aggs": { "actor_name": { "terms": { "field": "Starring.CastCrewName.keyword" }, "aggs": { "rating": { "avg": { "field": "StarRating" } } } } } } '
Take a moment to understand the variety of aggregation types
Pick an aggregation we did not cover in the slides and make it work
Last updated
Was this helpful?