We will use a bit more of Elasticsearch’s query DSL in this round of labs, and then use the enrich processor to add details of the National Olympic Committee.
This is the last round of exercises using the Olympics data. I encourage you to continue learning with the data.
If you enjoyed the exercises, please let me know. I’ll be posting solutions soon.
Write a query to return the first 50 documents for gold medal athletics events, in descending age order.
Write a query to match swimming events where either:
- The athlete’s weight was between 60kg and 70kg
- The athlete’s age was less than 20
Enhance the query so the results identify whether the weight, age, or both matched the search criteria.
Create a new index for the National Olympic Committees. Call it
olympic-noc-regions, with 1 primary shard and 0 replica shards. Ensure it has the following fields:
Index the data containing information about the National Olympic Committees using the Bulk API by following these steps:
Download the ND-JSON file from here.
Run the following command on the terminal:
curl -s -H "Content-Type: application/x-ndjson" --data-binary "@olympic-nocs.ndjson" http://localhost:9200/olympic-noc-regions/_bulk
Validate that the data was indexed correctly. The index should be green and contain 230 documents.
Create an enrich policy and ingest pipeline that uses the
enrich processor to add details of the National Olympic Committee to each document in the
olympic-events-fixed index. Call the policy
olympic-noc-append and the pipeline
enrich-noc. Add details of the matching NOC entry to a new field called
nocDetails, matching on the
Create a new index called
olympic-events-enriched, into which we can reindex the Olympic events but with some enriched fields. Change the mapping settings for the new index so we can add fields dynamically.
olympic-events-fixed index into
olympic-events-enriched, running it through the
enrich-noc ingest pipeline. Once complete, verify the new field was added to the
olympic-events-fixed index, and populated with details of the associated NOC.