Elasticsearch One Tip a Day: The Sense UI
This is the first post of what I hope will make a useful series on Elasticsearch. In this series I will share some tips and tricks I often give when working with various clients, or during courses or conference presentations.
In this post we will show-case Sense, the best Elasticsearch REST client out there. Even if you are already familiar with Sense, watch out for some pro-tips in the end.
What is Sense?
Elasticsearch exposes all its functionality via REST over HTTP, using JSON in requests and responses for everything from indexing data and querying it, to managing index and cluster configurations.
Memorizing all the endpoints and the entire DSL is frankly quite impossible to do, especially at the rate the Elasticsearch developers are moving at. For this, we have the Sense UI. Using this tool, you get auto-completion and intellisense on available endpoints, index and type names, the query DSL (including field names) and more.
Originally authored by Boaz Leskes as an open-source tool and a Chrome extension, it is now bundled with the Marvel product (which is non-free for non-development environments). So basically you have two version available, each one with its pros and cons:
The old Sense version, available as HTML and a Chrome extension. In case the unofficial Chrome extension goes down, you can still load the static files from here using Developer mode -> Load unpacked extension from Chrome settings. As this version isn't maintained, it will become stale as Elasticsearch itself changes. In fact, it is already stale as the Aggregation Framework isn't supported by its autocompletion. Yet, personally it is still my favorite because it is so easy to install and use.
Install Marvel locally or on your cluster, and use the Sense version provided with it. It is a bit of a more hassle to setup and use, but Sense is getting much love being part of Marvel and is up to speed with the latest and greatest.
Once you got Sense installed, you can type commands in the left pane, execute them against the Elasticsearch server (you can set the URL in the top bar of the Sense UI), and read the highlighted and prettified results in the right pane.
The format of commands Sense accepts is shown in the image below:
Already familiarized yourself with Sense? you may find the following pro-tips useful as well:
- Elasticsearch's documentation have all their examples using cURL. Instead of copying that over pieces by pieces, you can simply copy-paste the entire sample block directly. Sense will automatically transform cURL commands to its own syntax (VERB /endpoint/ followed by optional JSON in a new line).
- You can have multiple Elasticsearch commands typed in the left pane, and execute them selectively.
- Executing the currently highlighted command can be also done using Ctrl-Enter (Cmd-Enter on a Mac).
- Sense will memorize the commands you have on the left pane locally on your machine, so don't worry about closing that browser window.