2016-10-21 04:01:34 -05:00
+++
title = "Using Elasticsearch in Grafana"
description = "Guide for using Elasticsearch in Grafana"
keywords = ["grafana", "elasticsearch", "guide"]
type = "docs"
[menu.docs]
name = "Elasticsearch"
parent = "datasources"
weight = 3
+++
# Using Elasticsearch in Grafana
2015-10-26 07:36:00 -05:00
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.
## Adding the data source
2016-10-21 04:01:34 -05:00
2016-11-04 14:29:17 -05:00
![](/img/docs/v2/add_Graphite.jpg)
2015-10-26 07:36:00 -05:00
1. Open the side menu by clicking the the Grafana icon in the top header.
2. In the side menu under the `Dashboards` link you should find a link named `Data Sources` .
> NOTE: If this link is missing in the side menu it means that your current user does not have the `Admin` role for the current organization.
3. Click the `Add new` link in the top header.
4. Select `Elasticsearch` from the dropdown.
Name | Description
------------ | -------------
Name | The data source name, important that this is the same as in Grafana v1.x if you plan to import old dashboards.
Default | Default data source means that it will be pre-selected for new panels.
Url | The http protocol, ip and port of you elasticsearch server.
2016-07-02 10:27:31 -05:00
Access | Proxy = access via Grafana backend, Direct = access directly from browser.
2015-10-26 07:36:00 -05:00
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.
Direct access is still supported because in some cases it may be useful to access a Data Source directly depending on the use case and topology of Grafana, the user, and the Data Source.
### Direct access
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: "*"
### Index settings
2016-11-04 14:29:17 -05:00
![](/img/docs/elasticsearch/elasticsearch_ds_details.png)
2015-10-26 07:36:00 -05:00
2015-10-26 08:21:38 -05:00
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.
2015-10-26 07:36:00 -05:00
2015-10-26 08:21:38 -05:00
## Metric Query editor
2015-10-26 07:36:00 -05:00
2016-11-04 14:29:17 -05:00
![](/img/docs/elasticsearch/query_editor.png)
2015-10-26 07:36:00 -05:00
2015-10-26 08:21:38 -05:00
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.
2015-10-26 07:36:00 -05:00
2015-12-14 06:55:16 -06:00
## Pipeline metrics
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.
2016-11-04 14:29:17 -05:00
![](/img/docs/elasticsearch/pipeline_metrics_editor.png)
2015-12-14 06:55:16 -06:00
## Templating
The Elasticsearch datasource supports two types of queries you can use to fill template variables with values.
### Possible values for a field
```json
{"find": "terms", "field": "@hostname"}
```
### Fields filtered by type
```json
{"find": "fields", "type": "string"}
```
2016-01-04 23:48:47 -06:00
### Fields filtered by type, with filter
```json
{"find": "fields", "type": "string", "query": < lucene query > }
```
2015-12-14 06:55:16 -06:00
### Multi format / All format
Use lucene format.