Dev Tools and Console
Share:
Understanding and using Kibana Dev Tools and Console
Kibana Dev Tools provides a place within the Kibana interface to perform advanced actions on Elasticsearch data. An important part of Dev Tools is Console, which allows users to interact with the Elasticsearch RESTful API. In this tutorial, we will be taking the movie industry as a scenario to effectively demonstrate practical usage of the Kibana Dev Tools and Console.
To start with, Kibana needs to be correctly set up with Elasticsearch and you should have some data indexed. For our example, let's pretend we have indexed a sufficient amount of data relating to movies including their names, release dates, cast, and review ratings.
Let's begin with opening Dev Tools in Kibana. Click on the "Dev Tools" option in the navigational menu on the left side in Kibana's interface. Here, the console welcomes you with two panels. On the left, you write your requests, and the right one will show the server responses.
GET /movies/_search
By running the above command, you should receive a response on the right panel containing the indexed movie data.
The Console also supports auto-complete. Just start typing, and it will suggest context-appropriate possibilities based on your input.
Kibana Dev Tools provide a powerful and flexible way to test, debug and perform actions on your data. Let's discuss more operations you can execute using the Console.
- Indexing a Movie Document
We always need to update our movie database by adding new movies. In Elasticsearch, documents are stored in indices. To add a new movie to our movies index, we will use the HTTP verb POST.
POST /movies/_doc
{
"name": "Guardians of the Light",
"release_date" : "2021-10-22",
"cast": ["Tom Cruse", "Emma Watson"],
"rating": 8.5
}
After running this command, a new movie named ‘Guardians of the Light’ would be added to our movie database.
- Searching for a Specific Movie
Our movie fans might want to search for a specific movie to get its details. The GET command enables us to search for a movie by providing its unique ID.
GET /movies/_doc/1
This command will retrieve the movie with an ID of 1.
- Updating a Movie Document
Movie ratings might change over time based on users' reviews. Hence, we also need to update our data timely. For this operation, we will use the POST verb again, along with specifying a unique document ID.
POST /movies/_update/1
{
"doc": {
"rating": 9.1
}
}
This operation will update the rating of the movie with the ID of 1 in our database.
- Deleting a Movie Document
Sometimes, you might want to remove a movie from the database. Maybe the movie got removed from the theaters or didn't comply with your company's policy. The DELETE verb allows us to remove a specific movie by its ID.
DELETE /movies/_doc/1
This operation will delete the movie with an ID of 1 from the database.
- Bulk Operations
In some cases, you might want to perform multiple operations with one command. Bulk API in Elasticsearch allows us to perform multiple operations in a single API call, which increases the indexing speed.
POST /movies/_bulk
{"index":{ "_id":"1"}}
{"name":"Avengers Infinite War", "release_date":"2019-05-03", "rating":8.7, "cast":["Robert Downey Jr.", "Mark Ruffalo"]}
{"index":{ "_id":"2"}}
{"name":"Jurassic Jungle", "release_date":"2021-08-13", "rating":7.1, "cast":["Chris Pratt", "Bryce Dallas Howard"]}
Above bulk API operation will index two movie documents with the specified IDs in a single call.
Keep practicing with these commands and explore more, it will spice up your Elasticsearch journey. Kibana Dev Tools Console provides intuitive and user-friendly access to the Elasticsearch API which can make your querying and data manipulation task easier. Remember, practice is the key to become skilled in any tool, the same applies to the Kibana Dev Tools console. Happy analyzing your movie data!
0 Comment
Sign up or Log in to leave a comment