+++ title = "Using Elasticsearch in Grafana" description = "Guide for using Elasticsearch in Grafana" keywords = ["grafana", "elasticsearch", "guide"] type = "docs" aliases = ["/datasources/elasticsearch"] [menu.docs] name = "Elasticsearch" parent = "datasources" weight = 3 +++
Grafana ships with advanced support for Elasticsearch. You can do many types of simple or complex elasticsearch queries to visualize logs or metrics stored in elasticsearch. You can also annotate your graphs with log events stored in elasticsearch.
Dashboards link you should find a link named Data Sources.+ Add data source button in the top header.NOTE: If you're not seeing the
Data Sourceslink in your side menu it means that your current user does not have theAdminrole for the current organization.
| Name | Description |
|---|---|
| Name | The data source name. This is how you refer to the data source in panel metric queries. |
| Default | Default data source means that it will be pre-selected for new panels. |
| Url | The HTTP protocol, IP, and port of your graphite-web or graphite-api install. |
| Access | Proxy = access via Grafana backend, Direct = access directly from browser. |
Proxy access means that the Grafana backend will proxy all requests from the browser, and send them on to the Data Source. This is useful because it can eliminate CORS (Cross Origin Site Resource) issues, as well as eliminate the need to disseminate authentication details to the Data Source to the browser.
If you select direct access you must update your Elasticsearch configuration to allow other domains to access Elasticsearch from the browser. You do this by specifying these to options in your elasticsearch.yml config file.
http.cors.enabled: true
http.cors.allow-origin: "*"
Here you can specify a default for the time field and specify the name of your elasticsearch index. You can use
a time pattern for the index name or a wildcard.
The Elasticsearch query editor allows you to select multiple metrics and group by multiple terms or filters. Use the plus and minus icons to the right to add / remove metrics or group bys. Some metrics and group by have options, click the option text to expand the the row to view and edit metric or group by options.
You can control the name for time series via the Alias input field.
| Pattern | Description |
|---|---|
| {{term fieldname}} | replaced with value of a term group by |
| {{metric}} | replaced with metric name (ex. Average, Min, Max) |
| {{field}} | replaced with the metric field name |
If you have Elasticsearch 2.x and Grafana 2.6 or above then you can use pipeline metric aggregations like Moving Average and Derivative. Elasticsearch pipeline metrics require another metric to be based on. Use the eye icon next to the metric to hide metrics from appearing in the graph. This is useful for metrics you only have in the query to be used in a pipeline metric.
Instead of hard-coding things like server, application and sensor name in you metric queries you can use variables in their place. Variables are shown as dropdown select boxes at the top of the dashboard. These dropdowns makes it easy to change the data being displayed in your dashboard.
Checkout the Templating documentation for an introduction to the templating feature and the different types of template variables.
The Elasticsearch datasource supports two types of queries you can use in the Query field of Query variables.
The query is written using a custom json string.g
| Query | Description |
|---|---|
| *{"find": "fields", "type": "keyword"} | Returns a list of field names with the index type keyword. |
| {"find": "terms", "field": "@hostname"} | Returns a list of values for a field using term aggregation. Query will user current dashboard time range as time range for query. |
| {"find": "terms", "field": "@hostname", "query": ''} | Returns a list of values for a field using term aggregation & and a specified lucene query filter. Query will use current dashboard time range as time range for query. |
| Name | Description |
|---|---|
| Query | You can leave the search query blank or specify a lucene query |
| Time | The name of the time field, needs to be date field. |
| Title | The name of field to use for the event title. |
| Tags | Optional field name to use for event tags (can be array or csv string). |
| Text | Optional field name to use event text body. |