Last active
March 3, 2019 21:58
-
-
Save glenacota/b406017088aac1d795cb5d1196bcd351 to your computer and use it in GitHub Desktop.
An exercise to practice with the manipulation of indices in Elasticsearch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# GOAL: Create, update and delete indices while satisfying a given set of requirements | |
# INITIAL SETUP: (i) a running Elasticsearch cluster with at least one node and a Kibana instance, (ii) no index or index template that starts by `hamlet` | |
# Copy-paste the following instructions into your Kibana console, and work directly from there | |
# Create the index `hamlet-raw` with one primary shard and four replicas | |
# Add a document to `hamlet-raw`, so that the document (i) has id "1", (ii) has default type, (iii) has a field named `line` with value "To be, or not to be: that is the question" | |
# Update the document with id "1" by adding a field named `line_number` with value "3.1.64" | |
# Add a new document to `hamlet-raw`, so that the document (i) has no explicit id, (ii) has default type, (iii) has a field named `text_entry` with value "Whether tis nobler in the mind to suffer", (iv) has a field named `line_number` with value "3.1.66" | |
# Update the last document by setting the value of `line_number` to "3.1.65" | |
# In one request, update all documents in `hamlet-raw` by adding a new field named `speaker` with value "Hamlet" | |
# Update the document with id "1" by renaming the field `line` into `text_entry` | |
# Create the index `hamlet` and add some documents by running the following _bulk command | |
PUT hamlet/_doc/_bulk | |
{"index":{"_index":"hamlet","_id":0}} | |
{"line_number":"1.1.1","speaker":"BERNARDO","text_entry":"Whos there?"} | |
{"index":{"_index":"hamlet","_id":1}} | |
{"line_number":"1.1.2","speaker":"FRANCISCO","text_entry":"Nay, answer me: stand, and unfold yourself."} | |
{"index":{"_index":"hamlet","_id":2}} | |
{"line_number":"1.1.3","speaker":"BERNARDO","text_entry":"Long live the king!"} | |
{"index":{"_index":"hamlet","_id":3}} | |
{"line_number":"1.2.1","speaker":"KING CLAUDIUS","text_entry":"Though yet of Hamlet our dear brothers death"} | |
{"index":{"_index":"hamlet","_id":4}} | |
{"line_number":"1.2.2","speaker":"KING CLAUDIUS","text_entry":"The memory be green, and that it us befitted"} | |
{"index":{"_index":"hamlet","_id":5}} | |
{"line_number":"1.3.1","speaker":"LAERTES","text_entry":"My necessaries are embarkd: farewell:"} | |
{"index":{"_index":"hamlet","_id":6}} | |
{"line_number":"1.3.4","speaker":"LAERTES","text_entry":"But let me hear from you."} | |
{"index":{"_index":"hamlet","_id":7}} | |
{"line_number":"1.3.5","speaker":"OPHELIA","text_entry":"Do you doubt that?"} | |
{"index":{"_index":"hamlet","_id":8}} | |
{"line_number":"1.4.1","speaker":"HAMLET","text_entry":"The air bites shrewdly; it is very cold."} | |
{"index":{"_index":"hamlet","_id":9}} | |
{"line_number":"1.4.2","speaker":"HORATIO","text_entry":"It is a nipping and an eager air."} | |
{"index":{"_index":"hamlet","_id":10}} | |
{"line_number":"1.4.3","speaker":"HAMLET","text_entry":"What hour now?"} | |
{"index":{"_index":"hamlet","_id":11}} | |
{"line_number":"1.5.2","speaker":"Ghost","text_entry":"Mark me."} | |
{"index":{"_index":"hamlet","_id":12}} | |
{"line_number":"1.5.3","speaker":"HAMLET","text_entry":"I will."} | |
# Create a script named `set_is_hamlet` and save it into the cluster state. The script (i) adds a field named `is_hamlet` to each document, (ii) sets the field to "true" if the document has `speaker` equals to "HAMLET", (iii) sets the field to "false" otherwise | |
# Remove from `hamlet` the documents that have either "KING CLAUDIUS" or "LAERTES" as the value of `speaker` | |
# Delete all documents that start by "ham" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment