<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Elasticsearch data source on Grafana Labs</title><link>https://grafana.com/docs/grafana/v12.4/datasources/elasticsearch/</link><description>Recent content in Elasticsearch data source on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/grafana/v12.4/datasources/elasticsearch/index.xml" rel="self" type="application/rss+xml"/><item><title>Configure the Elasticsearch data source</title><link>https://grafana.com/docs/grafana/v12.4/datasources/elasticsearch/configure/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/datasources/elasticsearch/configure/</guid><content><![CDATA[&lt;h1 id=&#34;configure-the-elasticsearch-data-source&#34;&gt;Configure the Elasticsearch data source&lt;/h1&gt;
&lt;p&gt;Grafana ships with built-in support for Elasticsearch.
You can create a variety of queries to visualize logs or metrics stored in Elasticsearch, and annotate graphs with log events stored in Elasticsearch.&lt;/p&gt;
&lt;p&gt;For instructions on how to add a data source to Grafana, refer to the 
    &lt;a href=&#34;/docs/grafana/v12.4/administration/data-source-management/&#34;&gt;administration documentation&lt;/a&gt;.
Administrators can also &lt;a href=&#34;#provision-the-data-source&#34;&gt;configure the data source via YAML&lt;/a&gt; with Grafana&amp;rsquo;s provisioning system.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;p&gt;To configure the Elasticsearch data source, you need:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Grafana administrator permissions:&lt;/strong&gt; Only users with the organization &lt;code&gt;administrator&lt;/code&gt; role can add data sources.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;A supported Elasticsearch version:&lt;/strong&gt; v7.17 or later, v8.x, v9.x or Elastic Cloud Serverless.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Elasticsearch server URL:&lt;/strong&gt; The HTTP or HTTPS endpoint for your Elasticsearch instance, including the port (default: &lt;code&gt;9200&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Authentication credentials:&lt;/strong&gt; Depending on your Elasticsearch security configuration, you need one of the following:
&lt;ul&gt;
&lt;li&gt;Username and password for basic authentication&lt;/li&gt;
&lt;li&gt;API key&lt;/li&gt;
&lt;li&gt;No credentials (if Elasticsearch security is disabled)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Network access:&lt;/strong&gt; Grafana must be able to reach your Elasticsearch server. For Grafana Cloud, consider using &lt;a href=&#34;/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/&#34;&gt;Private data source connect (PDC)&lt;/a&gt; if your Elasticsearch instance is in a private network.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;elasticsearch-permissions&#34;&gt;Elasticsearch permissions&lt;/h2&gt;
&lt;p&gt;When Elasticsearch security features are enabled, you must configure the following cluster privileges for the user or API key that Grafana uses to connect:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;monitor&lt;/strong&gt; - Necessary to retrieve the version information of the connected Elasticsearch instance.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;view_index_metadata&lt;/strong&gt; - Required for accessing mapping definitions of indices.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;read&lt;/strong&gt; - Grants the ability to perform search and retrieval operations on indices. This is essential for querying and extracting data from the cluster.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;add-the-data-source&#34;&gt;Add the data source&lt;/h2&gt;
&lt;p&gt;To add the Elasticsearch data source, complete the following steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Click &lt;strong&gt;Connections&lt;/strong&gt; in the left-side menu.&lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;Connections&lt;/strong&gt;, click &lt;strong&gt;Add new connection&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Enter &lt;code&gt;Elasticsearch&lt;/code&gt; in the search bar.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Elasticsearch&lt;/strong&gt; under the &lt;strong&gt;Data source&lt;/strong&gt; section.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Add new data source&lt;/strong&gt; in the upper right.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You will be taken to the &lt;strong&gt;Settings&lt;/strong&gt; tab where you will set up your Elasticsearch configuration.&lt;/p&gt;
&lt;h2 id=&#34;configuration-options&#34;&gt;Configuration options&lt;/h2&gt;
&lt;p&gt;Configure the following basic settings for the Elasticsearch data source:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Name&lt;/strong&gt; - The data source name. This is how you refer to the data source in panels and queries. Examples: &lt;code&gt;elastic-1&lt;/code&gt;, &lt;code&gt;elasticsearch_metrics&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Default&lt;/strong&gt; - Toggle on to make this the default data source. New panels and Explore queries use the default data source.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;connection&#34;&gt;Connection&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;URL&lt;/strong&gt; - The URL of your Elasticsearch server, including the port. Examples: &lt;code&gt;http://localhost:9200&lt;/code&gt;, &lt;code&gt;http://elasticsearch.example.com:9200&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;authentication&#34;&gt;Authentication&lt;/h2&gt;
&lt;p&gt;Select an authentication method from the drop-down menu:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Basic authentication&lt;/strong&gt; - Enter the username and password for your Elasticsearch user.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Forward OAuth identity&lt;/strong&gt; - Forward the OAuth access token (and the OIDC ID token if available) of the user querying the data source.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;No authentication&lt;/strong&gt; - Connect without credentials. Only use this option if your Elasticsearch instance doesn&amp;rsquo;t require authentication.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;api-key-authentication&#34;&gt;API key authentication&lt;/h3&gt;
&lt;p&gt;To authenticate using an Elasticsearch API key, select &lt;strong&gt;No authentication&lt;/strong&gt; and configure the API key using HTTP headers:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;In the &lt;strong&gt;HTTP headers&lt;/strong&gt; section, click &lt;strong&gt;&#43; Add header&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Set &lt;strong&gt;Header&lt;/strong&gt; to &lt;code&gt;Authorization&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Set &lt;strong&gt;Value&lt;/strong&gt; to &lt;code&gt;ApiKey &amp;lt;your-api-key&amp;gt;&lt;/code&gt;, replacing &lt;code&gt;&amp;lt;your-api-key&amp;gt;&lt;/code&gt; with your base64-encoded Elasticsearch API key.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For information about creating API keys, refer to the &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Elasticsearch API keys documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;amazon-elasticsearch-service&#34;&gt;Amazon Elasticsearch Service&lt;/h3&gt;
&lt;p&gt;If you use Amazon Elasticsearch Service, you can use Grafana&amp;rsquo;s Elasticsearch data source to visualize data from it.&lt;/p&gt;
&lt;p&gt;If you use an AWS Identity and Access Management (IAM) policy to control access to your Amazon Elasticsearch Service domain, you must use AWS Signature Version 4 (AWS SigV4) to sign all requests to that domain.&lt;/p&gt;
&lt;p&gt;For details on AWS SigV4, refer to the &lt;a href=&#34;https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;AWS documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To sign requests to your Amazon Elasticsearch Service domain, you can enable SigV4 in Grafana&amp;rsquo;s 
    &lt;a href=&#34;/docs/grafana/v12.4/setup-grafana/configure-grafana/#sigv4_auth_enabled&#34;&gt;configuration&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Once AWS SigV4 is enabled, you can configure it on the Elasticsearch data source configuration page.
For more information about AWS authentication options, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/datasources/aws-cloudwatch/aws-authentication/&#34;&gt;AWS authentication&lt;/a&gt;.&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow&#34;
    style=&#34;max-width: 500px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link captioned&#34;
        href=&#34;/static/img/docs/v73/elasticsearch-sigv4-config-editor.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload mb-0&#34;
          data-src=&#34;/static/img/docs/v73/elasticsearch-sigv4-config-editor.png&#34;data-srcset=&#34;/static/img/docs/v73/elasticsearch-sigv4-config-editor.png?w=320 320w, /static/img/docs/v73/elasticsearch-sigv4-config-editor.png?w=550 550w, /static/img/docs/v73/elasticsearch-sigv4-config-editor.png?w=750 750w, /static/img/docs/v73/elasticsearch-sigv4-config-editor.png?w=900 900w, /static/img/docs/v73/elasticsearch-sigv4-config-editor.png?w=1040 1040w, /static/img/docs/v73/elasticsearch-sigv4-config-editor.png?w=1240 1240w, /static/img/docs/v73/elasticsearch-sigv4-config-editor.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;SigV4 configuration for AWS Elasticsearch Service&#34;width=&#34;759&#34;height=&#34;886&#34;title=&#34;SigV4 configuration for AWS Elasticsearch Service&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/v73/elasticsearch-sigv4-config-editor.png&#34;
            alt=&#34;SigV4 configuration for AWS Elasticsearch Service&#34;width=&#34;759&#34;height=&#34;886&#34;title=&#34;SigV4 configuration for AWS Elasticsearch Service&#34;class=&#34;docs-image--no-shadow&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;figcaption class=&#34;w-100p caption text-gray-13  &#34;&gt;SigV4 configuration for AWS Elasticsearch Service&lt;/figcaption&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;h3 id=&#34;tls-settings&#34;&gt;TLS settings&lt;/h3&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Use TLS (Transport Layer Security) for an additional layer of security when working with Elasticsearch. For information on setting up TLS encryption with Elasticsearch, refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/8.8/configuring-tls.html#configuring-tls&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Configure TLS&lt;/a&gt;. You must add TLS settings to your Elasticsearch configuration file &lt;strong&gt;prior&lt;/strong&gt; to setting these options in Grafana.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add self-signed certificate&lt;/strong&gt; - Check the box to authenticate with a CA certificate. Follow the instructions of the CA (Certificate Authority) to download the certificate file. Required for verifying self-signed TLS certificates.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;TLS client authentication&lt;/strong&gt; - Check the box to authenticate with the TLS client, where the server authenticates the client. Add the &lt;code&gt;Server name&lt;/code&gt;, &lt;code&gt;Client certificate&lt;/code&gt; and &lt;code&gt;Client key&lt;/code&gt;. The &lt;strong&gt;ServerName&lt;/strong&gt; is used to verify the hostname on the returned certificate. The &lt;strong&gt;Client certificate&lt;/strong&gt; can be generated from a Certificate Authority (CA) or be self-signed. The &lt;strong&gt;Client key&lt;/strong&gt; can also be generated from a Certificate Authority (CA) or be self-signed. The client key encrypts the data between client and server.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Skip TLS certificate validation&lt;/strong&gt; - Check the box to bypass TLS certificate validation. Skipping TLS certificate validation is not recommended unless absolutely necessary or for testing purposes.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;http-headers&#34;&gt;HTTP headers&lt;/h3&gt;
&lt;p&gt;Click &lt;strong&gt;&#43; Add header&lt;/strong&gt; to add one or more HTTP headers. HTTP headers pass additional context and metadata about the request/response.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Header&lt;/strong&gt; - Add a custom header. This allows custom headers to be passed based on the needs of your Elasticsearch instance.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Value&lt;/strong&gt; - The value of the header.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;additional-settings&#34;&gt;Additional settings&lt;/h2&gt;
&lt;p&gt;Additional settings are optional settings that can be configured for more control over your data source.&lt;/p&gt;
&lt;h3 id=&#34;advanced-http-settings&#34;&gt;Advanced HTTP settings&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Allowed cookies&lt;/strong&gt; - Specify cookies by name that should be forwarded to the data source. The Grafana proxy deletes all forwarded cookies by default.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Timeout&lt;/strong&gt; - The HTTP request timeout. This must be in seconds. There is no default, so this setting is up to you.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;elasticsearch-details&#34;&gt;Elasticsearch details&lt;/h3&gt;
&lt;p&gt;The following settings are specific to the Elasticsearch data source.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Index name&lt;/strong&gt; - The name of your Elasticsearch index. You can use the following formats:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Wildcard patterns&lt;/strong&gt; - Use &lt;code&gt;*&lt;/code&gt; to match multiple indices. Examples: &lt;code&gt;logs-*&lt;/code&gt;, &lt;code&gt;metrics-*&lt;/code&gt;, &lt;code&gt;filebeat-*&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Time patterns&lt;/strong&gt; - Use date placeholders for time-based indices. Wrap the fixed portion in square brackets. Examples: &lt;code&gt;[logstash-]YYYY.MM.DD&lt;/code&gt;, &lt;code&gt;[metrics-]YYYY.MM&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Specific index&lt;/strong&gt; - Enter the exact index name. Example: &lt;code&gt;application-logs&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Pattern&lt;/strong&gt; - Select the matching pattern if you use a time pattern in your index name. Options include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;no pattern&lt;/li&gt;
&lt;li&gt;hourly&lt;/li&gt;
&lt;li&gt;daily&lt;/li&gt;
&lt;li&gt;weekly&lt;/li&gt;
&lt;li&gt;monthly&lt;/li&gt;
&lt;li&gt;yearly&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Only select a pattern option if you have specified a time pattern in the Index name field.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Time field name&lt;/strong&gt; - Name of the time field. The default value is &lt;code&gt;@timestamp&lt;/code&gt;. You can enter a different name.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Max concurrent shard requests&lt;/strong&gt; - Sets the number of shards being queried at the same time. The default is &lt;code&gt;5&lt;/code&gt;. For more information on shards, refer to the &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/8.9/scalability.html#scalability&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Elasticsearch documentation&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Min time interval&lt;/strong&gt; - Defines a lower limit for the auto group-by time interval. This value &lt;strong&gt;must&lt;/strong&gt; be formatted as a number followed by a valid time identifier:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Identifier&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;y&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;year&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;M&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;month&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;w&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;week&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;d&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;day&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;h&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;hour&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;m&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;minute&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;s&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;second&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;ms&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;millisecond&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We recommend setting this value to match your Elasticsearch write frequency.
For example, set this to &lt;code&gt;1m&lt;/code&gt; if Elasticsearch writes data every minute.&lt;/p&gt;
&lt;p&gt;You can also override this setting in a dashboard panel under its data source options. The default is &lt;code&gt;10s&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;X-Pack enabled&lt;/strong&gt; - Toggle to enable &lt;code&gt;X-Pack&lt;/code&gt;-specific features and options, which provide the 
    &lt;a href=&#34;/docs/grafana/v12.4/datasources/elasticsearch/query-editor/&#34;&gt;query editor&lt;/a&gt; with additional aggregations, such as &lt;code&gt;Rate&lt;/code&gt; and &lt;code&gt;Top Metrics&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Include frozen indices&lt;/strong&gt; - Toggle on when the &lt;code&gt;X-Pack enabled&lt;/code&gt; setting is active. Includes frozen indices in searches. You can configure Grafana to include &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/7.13/frozen-indices.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;frozen indices&lt;/a&gt; when performing search requests.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Frozen indices are &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/7.17/frozen-indices.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;deprecated in Elasticsearch&lt;/a&gt; since v7.14.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h3 id=&#34;logs&#34;&gt;Logs&lt;/h3&gt;
&lt;p&gt;Configure which fields the data source uses for log messages and log levels.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Message field name&lt;/strong&gt; - The field that contains the log message content.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Level field name&lt;/strong&gt; - The field that contains log level or severity information. When specified, Grafana uses this field to determine the log level and color-code each log line. If the log doesn&amp;rsquo;t have a level field, Grafana tries to match the content against 
    &lt;a href=&#34;/docs/grafana/v12.4/explore/logs-integration/#log-level&#34;&gt;supported expressions&lt;/a&gt;. If Grafana can&amp;rsquo;t determine the log level, it displays as unknown.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;data-links&#34;&gt;Data links&lt;/h3&gt;
&lt;p&gt;Data links create a link from a specified field that can be accessed in Explore&amp;rsquo;s logs view. You can add multiple data links by clicking &lt;strong&gt;&#43; Add&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Each data link configuration consists of:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Field&lt;/strong&gt; - Sets the name of the field used by the data link.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;URL/query&lt;/strong&gt; - Sets the full link URL if the link is external. If the link is internal, this input serves as a query for the target data source.&lt;br/&gt;In both cases, you can interpolate the value from the field with the &lt;code&gt;${__value.raw }&lt;/code&gt; macro.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;URL Label&lt;/strong&gt; (Optional) - Sets a custom display label for the link. The link label defaults to the full external URL or name of the linked internal data source and is overridden by this setting.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Internal link&lt;/strong&gt; - Toggle on to set an internal link. For an internal link, you can select the target data source with a data source selector. This supports only tracing data sources.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;private-data-source-connect-pdc-and-elasticsearch&#34;&gt;Private data source connect (PDC) and Elasticsearch&lt;/h2&gt;
&lt;p&gt;Use private data source connect (PDC) to connect to and query data within a secure network without opening that network to inbound traffic from Grafana Cloud. Refer to &lt;a href=&#34;/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/&#34;&gt;Private data source connect&lt;/a&gt; for more information on how PDC works and &lt;a href=&#34;/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/configure-pdc/#configure-grafana-private-data-source-connect-pdc&#34;&gt;Configure Grafana private data source connect (PDC)&lt;/a&gt; for steps on setting up a PDC connection.&lt;/p&gt;
&lt;p&gt;If you use PDC with SigV4 (AWS Signature Version 4 Authentication), the PDC agent must allow internet egress to &lt;code&gt;sts.&amp;lt;region&amp;gt;.amazonaws.com:443&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Private data source connect&lt;/strong&gt; - Click in the box to set the default PDC connection from the drop-down menu or create a new connection.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Once you have configured your Elasticsearch data source options, click &lt;strong&gt;Save &amp;amp; test&lt;/strong&gt; to test the connection. A successful connection displays the following message:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Elasticsearch data source is healthy.&lt;/code&gt;&lt;/p&gt;
&lt;h2 id=&#34;provision-the-data-source&#34;&gt;Provision the data source&lt;/h2&gt;
&lt;p&gt;You can define and configure the data source in YAML files as part of Grafana&amp;rsquo;s provisioning system.
For more information about provisioning, and for available configuration options, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/administration/provisioning/&#34;&gt;Provisioning Grafana&lt;/a&gt;.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;The previously used &lt;code&gt;database&lt;/code&gt; field has now been &lt;a href=&#34;https://github.com/grafana/grafana/pull/58647&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;deprecated&lt;/a&gt;.
Use the &lt;code&gt;index&lt;/code&gt; field in &lt;code&gt;jsonData&lt;/code&gt; to store the index name.
Refer to the examples below.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h3 id=&#34;basic-provisioning&#34;&gt;Basic provisioning&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;apiVersion: 1

datasources:
  - name: Elastic
    type: elasticsearch
    access: proxy
    url: http://localhost:9200
    jsonData:
      index: &amp;#39;[metrics-]YYYY.MM.DD&amp;#39;
      interval: Daily
      timeField: &amp;#39;@timestamp&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;provision-for-logs&#34;&gt;Provision for logs&lt;/h3&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;apiVersion: 1

datasources:
  - name: elasticsearch-v7-filebeat
    type: elasticsearch
    access: proxy
    url: http://localhost:9200
    jsonData:
      index: &amp;#39;[filebeat-]YYYY.MM.DD&amp;#39;
      interval: Daily
      timeField: &amp;#39;@timestamp&amp;#39;
      logMessageField: message
      logLevelField: fields.level
      dataLinks:
        - datasourceUid: my_jaeger_uid # Target UID needs to be known
          field: traceID
          url: &amp;#39;$${__value.raw}&amp;#39; # Careful about the double &amp;#34;$$&amp;#34; because of env var expansion&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;provision-the-data-source-using-terraform&#34;&gt;Provision the data source using Terraform&lt;/h2&gt;
&lt;p&gt;You can provision the Elasticsearch data source using &lt;a href=&#34;https://www.terraform.io/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Terraform&lt;/a&gt; with the &lt;a href=&#34;https://registry.terraform.io/providers/grafana/grafana/latest/docs&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana Terraform provider&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For more information about provisioning resources with Terraform, refer to the &lt;a href=&#34;/docs/grafana-cloud/developer-resources/infrastructure-as-code/terraform/&#34;&gt;Grafana as code using Terraform&lt;/a&gt; documentation.&lt;/p&gt;
&lt;h3 id=&#34;basic-terraform-example&#34;&gt;Basic Terraform example&lt;/h3&gt;
&lt;p&gt;The following example creates a basic Elasticsearch data source for metrics:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;hcl&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-hcl&#34;&gt;resource &amp;#34;grafana_data_source&amp;#34; &amp;#34;elasticsearch&amp;#34; {
  name = &amp;#34;Elasticsearch&amp;#34;
  type = &amp;#34;elasticsearch&amp;#34;
  url  = &amp;#34;http://localhost:9200&amp;#34;

  json_data_encoded = jsonencode({
    index     = &amp;#34;[metrics-]YYYY.MM.DD&amp;#34;
    interval  = &amp;#34;Daily&amp;#34;
    timeField = &amp;#34;@timestamp&amp;#34;
  })
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;terraform-example-for-logs&#34;&gt;Terraform example for logs&lt;/h3&gt;
&lt;p&gt;The following example creates an Elasticsearch data source configured for logs with a data link to Jaeger:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;hcl&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-hcl&#34;&gt;resource &amp;#34;grafana_data_source&amp;#34; &amp;#34;elasticsearch_logs&amp;#34; {
  name = &amp;#34;Elasticsearch Logs&amp;#34;
  type = &amp;#34;elasticsearch&amp;#34;
  url  = &amp;#34;http://localhost:9200&amp;#34;

  json_data_encoded = jsonencode({
    index           = &amp;#34;[filebeat-]YYYY.MM.DD&amp;#34;
    interval        = &amp;#34;Daily&amp;#34;
    timeField       = &amp;#34;@timestamp&amp;#34;
    logMessageField = &amp;#34;message&amp;#34;
    logLevelField   = &amp;#34;fields.level&amp;#34;
    dataLinks = [
      {
        datasourceUid = grafana_data_source.jaeger.uid
        field         = &amp;#34;traceID&amp;#34;
        url           = &amp;#34;$${__value.raw}&amp;#34;
      }
    ]
  })
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;terraform-example-with-basic-authentication&#34;&gt;Terraform example with basic authentication&lt;/h3&gt;
&lt;p&gt;The following example includes basic authentication:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;hcl&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-hcl&#34;&gt;resource &amp;#34;grafana_data_source&amp;#34; &amp;#34;elasticsearch_auth&amp;#34; {
  name = &amp;#34;Elasticsearch&amp;#34;
  type = &amp;#34;elasticsearch&amp;#34;
  url  = &amp;#34;http://localhost:9200&amp;#34;

  basic_auth_enabled  = true
  basic_auth_username = &amp;#34;elastic_user&amp;#34;

  secure_json_data_encoded = jsonencode({
    basicAuthPassword = var.elasticsearch_password
  })

  json_data_encoded = jsonencode({
    index     = &amp;#34;[metrics-]YYYY.MM.DD&amp;#34;
    interval  = &amp;#34;Daily&amp;#34;
    timeField = &amp;#34;@timestamp&amp;#34;
  })
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For all available configuration options, refer to the &lt;a href=&#34;https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/data_source&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana provider data source resource documentation&lt;/a&gt;.&lt;/p&gt;
]]></content><description>&lt;h1 id="configure-the-elasticsearch-data-source">Configure the Elasticsearch data source&lt;/h1>
&lt;p>Grafana ships with built-in support for Elasticsearch.
You can create a variety of queries to visualize logs or metrics stored in Elasticsearch, and annotate graphs with log events stored in Elasticsearch.&lt;/p></description></item><item><title>Elasticsearch query editor</title><link>https://grafana.com/docs/grafana/v12.4/datasources/elasticsearch/query-editor/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/datasources/elasticsearch/query-editor/</guid><content><![CDATA[&lt;h1 id=&#34;elasticsearch-query-editor&#34;&gt;Elasticsearch query editor&lt;/h1&gt;
&lt;p&gt;Grafana provides a query editor for Elasticsearch. Elasticsearch queries are in Lucene format.
For more information about query syntax, refer to &lt;a href=&#34;https://www.elastic.co/guide/en/kibana/current/lucene-query.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Lucene query syntax&lt;/a&gt; and &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-syntax&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Query string syntax&lt;/a&gt;.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;When composing Lucene queries, ensure that you use uppercase boolean operators: &lt;code&gt;AND&lt;/code&gt;, &lt;code&gt;OR&lt;/code&gt;, and &lt;code&gt;NOT&lt;/code&gt;. Lowercase versions of these operators are not supported by the Lucene query syntax.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow&#34;
    style=&#34;max-width: 800px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link captioned&#34;
        href=&#34;/static/img/docs/elasticsearch/elastic-query-editor-10.1.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload mb-0&#34;
          data-src=&#34;/static/img/docs/elasticsearch/elastic-query-editor-10.1.png&#34;data-srcset=&#34;/static/img/docs/elasticsearch/elastic-query-editor-10.1.png?w=320 320w, /static/img/docs/elasticsearch/elastic-query-editor-10.1.png?w=550 550w, /static/img/docs/elasticsearch/elastic-query-editor-10.1.png?w=750 750w, /static/img/docs/elasticsearch/elastic-query-editor-10.1.png?w=900 900w, /static/img/docs/elasticsearch/elastic-query-editor-10.1.png?w=1040 1040w, /static/img/docs/elasticsearch/elastic-query-editor-10.1.png?w=1240 1240w, /static/img/docs/elasticsearch/elastic-query-editor-10.1.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;Elasticsearch query editor&#34;width=&#34;1844&#34;height=&#34;266&#34;title=&#34;Elasticsearch query editor&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/elasticsearch/elastic-query-editor-10.1.png&#34;
            alt=&#34;Elasticsearch query editor&#34;width=&#34;1844&#34;height=&#34;266&#34;title=&#34;Elasticsearch query editor&#34;class=&#34;docs-image--no-shadow&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;figcaption class=&#34;w-100p caption text-gray-13  &#34;&gt;Elasticsearch query editor&lt;/figcaption&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;For general documentation on querying data sources in Grafana, including options and functions common to all query editors, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/panels-visualizations/query-transform-data/&#34;&gt;Query and transform data&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;aggregation-types&#34;&gt;Aggregation types&lt;/h2&gt;
&lt;p&gt;Elasticsearch groups aggregations into three categories:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Bucket&lt;/strong&gt; - Bucket aggregations don&amp;rsquo;t calculate metrics, they create buckets of documents based on field values, ranges and a variety of other criteria. Refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Bucket aggregations&lt;/a&gt; for additional information. Use bucket aggregations under &lt;code&gt;Group by&lt;/code&gt; when creating a metrics query in the query builder.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Metrics&lt;/strong&gt; - Metrics aggregations perform calculations such as sum, average, min, etc. They can be single-value or multi-value. Refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Metrics aggregations&lt;/a&gt; for additional information. Use metrics aggregations in the metrics query type in the query builder.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Pipeline&lt;/strong&gt; - Pipeline aggregations work on the output of other aggregations rather than on documents or fields. Refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Pipeline aggregations&lt;/a&gt; for additional information.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;select-a-query-type&#34;&gt;Select a query type&lt;/h2&gt;
&lt;p&gt;There are three types of queries you can create with the Elasticsearch query builder. Each type is explained in detail below.&lt;/p&gt;
&lt;h3 id=&#34;metrics-query-type&#34;&gt;Metrics query type&lt;/h3&gt;
&lt;p&gt;Metrics queries aggregate data and produce calculations such as count, min, max, and more. Click the metric box to view options in the drop-down menu. The default is &lt;code&gt;count&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Alias&lt;/strong&gt; - Aliasing only applies to &lt;strong&gt;time series queries&lt;/strong&gt;, where the last group is &lt;code&gt;date histogram&lt;/code&gt;. This is ignored for any other type of query.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Metric&lt;/strong&gt; - Metrics aggregations include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;count - refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Value count aggregation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;average - refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Avg aggregation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;sum - refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Sum aggregation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;max - refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Max aggregation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;min - refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-min-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Min aggregation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;extended stats - refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-extendedstats-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Extended stats aggregation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;percentiles - refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Percentiles aggregation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;unique count - refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Cardinality aggregation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;top metrics - refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-metrics.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Top metrics aggregation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;rate - refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-rate-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Rate aggregation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Pipeline aggregations&lt;/strong&gt; - Pipeline aggregations work on the output of other aggregations rather than on documents. The following pipeline aggregations are available:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;moving function - Calculates a value based on a sliding window of aggregated values. Refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-movfn-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Moving function aggregation&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;derivative - Calculates the derivative of a metric. Refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-derivative-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Derivative aggregation&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;cumulative sum - Calculates the cumulative sum of a metric. Refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-cumulative-sum-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Cumulative sum aggregation&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;serial difference - Calculates the difference between values in a time series. Refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-serialdiff-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Serial differencing aggregation&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;bucket script - Executes a script on metric values from other aggregations. Refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Bucket script aggregation&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can select multiple metrics and group by multiple terms or filters when using the Elasticsearch query editor.&lt;/p&gt;
&lt;p&gt;Use the &lt;strong&gt;&#43; sign&lt;/strong&gt; to the right to add multiple metrics to your query. Click on the &lt;strong&gt;eye icon&lt;/strong&gt; next to &lt;strong&gt;Metric&lt;/strong&gt; to hide metrics, and the &lt;strong&gt;garbage can icon&lt;/strong&gt; to remove metrics.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Group by options&lt;/strong&gt; - Create multiple group by options when constructing your Elasticsearch query. Date histogram is the default option. The following options are available in the drop-down menu:
&lt;ul&gt;
&lt;li&gt;terms - refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Terms aggregation&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;filter - refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Filter aggregation&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;geo hash grid - refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Geohash grid aggregation&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;date histogram - for time series queries. Refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Date histogram aggregation&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;histogram - Depicts frequency distributions. Refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Histogram aggregation&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;nested (experimental) - Refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Nested aggregation&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Each group by option will have a different subset of options to further narrow your query.&lt;/p&gt;
&lt;p&gt;The following options are specific to the &lt;strong&gt;date histogram&lt;/strong&gt; bucket aggregation option.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Time field&lt;/strong&gt; - The field used for time-based queries. The default can be set when configuring the data source in the &lt;strong&gt;Time field name&lt;/strong&gt; setting under 
    &lt;a href=&#34;/docs/grafana/v12.4/datasources/elasticsearch/configure/#elasticsearch-details&#34;&gt;Elasticsearch details&lt;/a&gt;. The default is &lt;code&gt;@timestamp&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Interval&lt;/strong&gt; - The time interval for grouping data. Select from the drop-down menu or enter a custom interval such as &lt;code&gt;30d&lt;/code&gt; (30 days). The default is &lt;code&gt;Auto&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Min doc count&lt;/strong&gt; - The minimum number of documents required to include a bucket. The default is &lt;code&gt;0&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Trim edges&lt;/strong&gt; - Removes partial buckets at the edges of the time range. The default is &lt;code&gt;0&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Offset&lt;/strong&gt; - Shifts the start of each bucket by the specified duration. Use positive (&lt;code&gt;&#43;&lt;/code&gt;) or negative (&lt;code&gt;-&lt;/code&gt;) values. Examples: &lt;code&gt;1h&lt;/code&gt;, &lt;code&gt;5s&lt;/code&gt;, &lt;code&gt;1d&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Timezone&lt;/strong&gt; - The timezone for date calculations. The default is &lt;code&gt;Coordinated Universal Time&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Configure the following options for the &lt;strong&gt;terms&lt;/strong&gt; bucket aggregation option:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Order&lt;/strong&gt; - Sets the order of data. Options are &lt;code&gt;top&lt;/code&gt; or &lt;code&gt;bottom.&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Size&lt;/strong&gt; - Limits the number of documents, or size of the data set. You can set a custom number or &lt;code&gt;no limit&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Min doc count&lt;/strong&gt; - The minimum amount of data to include in your query. The default is &lt;code&gt;0&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Order by&lt;/strong&gt; - Order terms by &lt;code&gt;term value&lt;/code&gt;, &lt;code&gt;doc count&lt;/code&gt; or &lt;code&gt;count&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Missing&lt;/strong&gt; - Defines how documents missing a value should be treated. Missing values are ignored by default, but they can be treated as if they had a value. Refer to &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#_missing_value_5&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Missing value&lt;/a&gt; in the Elasticsearch documentation for more information.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Configure the following options for the &lt;strong&gt;filters&lt;/strong&gt; bucket aggregation option:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Query&lt;/strong&gt; - Specify the query to create a bucket of documents (data). Examples are &lt;code&gt;hostname:&amp;quot;hostname1&amp;quot;&lt;/code&gt;, &lt;code&gt;product:&amp;quot;widget5&amp;quot;&lt;/code&gt;. Use the * wildcard to match any number of characters.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Label&lt;/strong&gt; - Add a label or name to the bucket.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Configure the following options for the &lt;strong&gt;geo hash grid&lt;/strong&gt; bucket aggregation option:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Precision&lt;/strong&gt; - Specifies the number of characters of the geo hash.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Configure the following options for the &lt;strong&gt;histogram&lt;/strong&gt; bucket aggregation option:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Interval&lt;/strong&gt; - The numeric interval for grouping values into buckets.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Min doc count&lt;/strong&gt; - The minimum number of documents required to include a bucket. The default is &lt;code&gt;0&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The &lt;strong&gt;nested&lt;/strong&gt; group by option is currently experimental, you can select a field and then settings specific to that field.&lt;/p&gt;
&lt;p&gt;Click the &lt;strong&gt;&#43; sign&lt;/strong&gt; to add multiple group by options. The data will grouped in order (first by, then by).&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow&#34;
    style=&#34;max-width: 850px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link captioned&#34;
        href=&#34;/static/img/docs/elasticsearch/group-by-then-by-10.2.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload mb-0&#34;
          data-src=&#34;/static/img/docs/elasticsearch/group-by-then-by-10.2.png&#34;data-srcset=&#34;/static/img/docs/elasticsearch/group-by-then-by-10.2.png?w=320 320w, /static/img/docs/elasticsearch/group-by-then-by-10.2.png?w=550 550w, /static/img/docs/elasticsearch/group-by-then-by-10.2.png?w=750 750w, /static/img/docs/elasticsearch/group-by-then-by-10.2.png?w=900 900w, /static/img/docs/elasticsearch/group-by-then-by-10.2.png?w=1040 1040w, /static/img/docs/elasticsearch/group-by-then-by-10.2.png?w=1240 1240w, /static/img/docs/elasticsearch/group-by-then-by-10.2.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;Group by options&#34;width=&#34;1614&#34;height=&#34;565&#34;title=&#34;Group by options&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/elasticsearch/group-by-then-by-10.2.png&#34;
            alt=&#34;Group by options&#34;width=&#34;1614&#34;height=&#34;565&#34;title=&#34;Group by options&#34;class=&#34;docs-image--no-shadow&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;figcaption class=&#34;w-100p caption text-gray-13  &#34;&gt;Group by options&lt;/figcaption&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;h3 id=&#34;logs-query-type&#34;&gt;Logs query type&lt;/h3&gt;
&lt;p&gt;Logs queries analyze Elasticsearch log data. You can configure the following options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Logs Options/Limit&lt;/strong&gt; - Limits the number of logs to analyze. The default is &lt;code&gt;500&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;raw-data-query-type&#34;&gt;Raw data query type&lt;/h3&gt;
&lt;p&gt;Run a raw data query to retrieve a table of all fields that are associated with each log line.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Raw data size&lt;/strong&gt; - Number of raw data documents. You can specify a different amount. The default is &lt;code&gt;500&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;The option to run a &lt;strong&gt;raw document query&lt;/strong&gt; is deprecated as of Grafana v10.1.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;raw-query-editor&#34;&gt;Raw query editor&lt;/h2&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;The raw query editor is an experimental feature that must be enabled using the &lt;code&gt;elasticsearchRawDSLQuery&lt;/code&gt; 
    &lt;a href=&#34;/docs/grafana/v12.4/setup-grafana/configure-grafana/feature-toggles/&#34;&gt;feature toggle&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;The raw query editor allows you to write Elasticsearch queries using the native &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Elasticsearch Query DSL&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;switch-between-builder-and-code-modes&#34;&gt;Switch between Builder and Code modes&lt;/h3&gt;
&lt;p&gt;To access the raw query editor, click the &lt;strong&gt;Code&lt;/strong&gt; toggle in the top-right corner of the query editor. You can switch between &lt;strong&gt;Builder&lt;/strong&gt; and &lt;strong&gt;Code&lt;/strong&gt; modes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Builder&lt;/strong&gt; - Visual query builder with dropdown menus and forms&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Code&lt;/strong&gt; - JSON editor for writing raw Elasticsearch DSL queries&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;write-raw-dsl-queries&#34;&gt;Write raw DSL queries&lt;/h3&gt;
&lt;p&gt;When in Code mode, you can write complete Elasticsearch query DSL in JSON format. The editor provides:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Syntax highlighting&lt;/strong&gt; for JSON&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Auto-formatting&lt;/strong&gt; - Click the &lt;strong&gt;Format&lt;/strong&gt; button or press &lt;code&gt;Shift&#43;Alt&#43;F&lt;/code&gt; to format your query&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Keyboard shortcuts&lt;/strong&gt; - Press &lt;code&gt;Ctrl&#43;Enter&lt;/code&gt; (or &lt;code&gt;Cmd&#43;Enter&lt;/code&gt; on Mac) to run the query&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Real-time validation&lt;/strong&gt; - Invalid JSON will be highlighted with error messages&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;time-range-handling&#34;&gt;Time range handling&lt;/h3&gt;
&lt;p&gt;If you want to filter by time range in a dashboard, you need to use the &lt;code&gt;$__from&lt;/code&gt; and &lt;code&gt;$__to&lt;/code&gt; macros in your raw DSL.&lt;/p&gt;
&lt;p&gt;An example query applying dashboard time range using the &lt;code&gt;@timestamp&lt;/code&gt; field:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JSON&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-json&#34;&gt;{
  &amp;#34;query&amp;#34;: {
    &amp;#34;bool&amp;#34;: {
      &amp;#34;must&amp;#34;: [
        {
          &amp;#34;range&amp;#34;: {
            &amp;#34;@timestamp&amp;#34;: {
              &amp;#34;gte&amp;#34;: &amp;#34;$__from&amp;#34;,
              &amp;#34;lte&amp;#34;: &amp;#34;$__to&amp;#34;,
              &amp;#34;format&amp;#34;: &amp;#34;epoch_millis&amp;#34;
            }
          }
        }
      ]
    }
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;supported-query-types&#34;&gt;Supported query types&lt;/h3&gt;
&lt;p&gt;The raw query editor supports all query types:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Metrics queries&lt;/strong&gt; are used to query time series data with aggregations. The query parser will automatically extract bucket and metric aggregations from your DSL and use them for response processing.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Logs queries&lt;/strong&gt; are used to query log data.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Raw data queries&lt;/strong&gt; are used for document-level data retrieval.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;use-template-variables&#34;&gt;Use template variables&lt;/h2&gt;
&lt;p&gt;You can also augment queries by using 
    &lt;a href=&#34;/docs/grafana/v12.4/datasources/elasticsearch/template-variables/&#34;&gt;template variables&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Queries of &lt;code&gt;terms&lt;/code&gt; have a 500-result limit by default.
To set a custom limit, set the &lt;code&gt;size&lt;/code&gt; property in your query.&lt;/p&gt;
]]></content><description>&lt;h1 id="elasticsearch-query-editor">Elasticsearch query editor&lt;/h1>
&lt;p>Grafana provides a query editor for Elasticsearch. Elasticsearch queries are in Lucene format.
For more information about query syntax, refer to &lt;a href="https://www.elastic.co/guide/en/kibana/current/lucene-query.html" target="_blank" rel="noopener noreferrer">Lucene query syntax&lt;/a> and &lt;a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-syntax" target="_blank" rel="noopener noreferrer">Query string syntax&lt;/a>.&lt;/p></description></item><item><title>Elasticsearch template variables</title><link>https://grafana.com/docs/grafana/v12.4/datasources/elasticsearch/template-variables/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/datasources/elasticsearch/template-variables/</guid><content><![CDATA[&lt;h1 id=&#34;elasticsearch-template-variables&#34;&gt;Elasticsearch template variables&lt;/h1&gt;
&lt;p&gt;Instead of hard-coding details such as server, application, and sensor names in metric queries, you can use variables.
Grafana lists these variables in drop-down select boxes at the top of the dashboard to help you change the data displayed in your dashboard.
Grafana refers to such variables as template variables.&lt;/p&gt;
&lt;p&gt;For an introduction to templating and template variables, refer to the 
    &lt;a href=&#34;/docs/grafana/v12.4/dashboards/variables/&#34;&gt;Templating&lt;/a&gt; and 
    &lt;a href=&#34;/docs/grafana/v12.4/dashboards/variables/add-template-variables/&#34;&gt;Add and manage variables&lt;/a&gt; documentation.&lt;/p&gt;
&lt;h2 id=&#34;use-ad-hoc-filters&#34;&gt;Use ad hoc filters&lt;/h2&gt;
&lt;p&gt;Elasticsearch supports the &lt;strong&gt;Ad hoc filters&lt;/strong&gt; variable type.
You can use this variable type to specify any number of key/value filters, and Grafana applies them automatically to all of your Elasticsearch queries.&lt;/p&gt;
&lt;p&gt;Ad hoc filters support the following operators:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Operator&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;=&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Equals. Adds &lt;code&gt;AND field:&amp;quot;value&amp;quot;&lt;/code&gt; to the query.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;!=&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Not equals. Adds &lt;code&gt;AND -field:&amp;quot;value&amp;quot;&lt;/code&gt; to the query.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;=~&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Matches regex. Adds &lt;code&gt;AND field:/value/&lt;/code&gt; to the query.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;!~&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Does not match regex. Adds &lt;code&gt;AND -field:/value/&lt;/code&gt; to the query.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Greater than. Adds &lt;code&gt;AND field:&amp;gt;value&lt;/code&gt; to the query.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Less than. Adds &lt;code&gt;AND field:&amp;lt;value&lt;/code&gt; to the query.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;For more information, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/dashboards/variables/add-template-variables/#add-ad-hoc-filters&#34;&gt;Add ad hoc filters&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;choose-a-variable-syntax&#34;&gt;Choose a variable syntax&lt;/h2&gt;
&lt;p&gt;The Elasticsearch data source supports two variable syntaxes for use in the &lt;strong&gt;Query&lt;/strong&gt; field:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;$varname&lt;/code&gt;, such as &lt;code&gt;hostname:$hostname&lt;/code&gt;, which is easy to read and write but doesn&amp;rsquo;t let you use a variable in the middle of a word.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;[[varname]]&lt;/code&gt;, such as &lt;code&gt;hostname:[[hostname]]&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When the &lt;em&gt;Multi-value&lt;/em&gt; or &lt;em&gt;Include all value&lt;/em&gt; options are enabled, Grafana converts the labels from plain text to a Lucene-compatible condition.
For details, refer to the 
    &lt;a href=&#34;/docs/grafana/v12.4/dashboards/variables/add-template-variables/#multi-value-variables&#34;&gt;Multi-value variables&lt;/a&gt; documentation.&lt;/p&gt;
&lt;h2 id=&#34;use-variables-in-queries&#34;&gt;Use variables in queries&lt;/h2&gt;
&lt;p&gt;You can use variables in the Lucene query field, metric aggregation fields, bucket aggregation fields, and the alias field.&lt;/p&gt;
&lt;h3 id=&#34;variables-in-lucene-queries&#34;&gt;Variables in Lucene queries&lt;/h3&gt;
&lt;p&gt;Use variables to filter your Elasticsearch queries dynamically:&lt;/p&gt;

&lt;div class=&#34;code-snippet code-snippet__mini&#34;&gt;&lt;div class=&#34;lang-toolbar__mini&#34;&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet code-snippet__border&#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-none&#34;&gt;hostname:$hostname AND level:$level&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;chain-or-nest-variables&#34;&gt;Chain or nest variables&lt;/h3&gt;
&lt;p&gt;You can create nested variables, where one variable&amp;rsquo;s values depend on another variable&amp;rsquo;s selection.&lt;/p&gt;
&lt;p&gt;This example defines a variable named &lt;code&gt;$host&lt;/code&gt; that only shows hosts matching the selected &lt;code&gt;$environment&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JSON&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-json&#34;&gt;{ &amp;#34;find&amp;#34;: &amp;#34;terms&amp;#34;, &amp;#34;field&amp;#34;: &amp;#34;hostname&amp;#34;, &amp;#34;query&amp;#34;: &amp;#34;environment:$environment&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Whenever you change the value of the &lt;code&gt;$environment&lt;/code&gt; variable via the drop-down, Grafana triggers an update of the &lt;code&gt;$host&lt;/code&gt; variable to contain only hostnames filtered by the selected environment.&lt;/p&gt;
&lt;h3 id=&#34;variables-in-aggregations&#34;&gt;Variables in aggregations&lt;/h3&gt;
&lt;p&gt;You can use variables in bucket aggregation fields to dynamically change how data is grouped. For example, use a variable in the &lt;strong&gt;Terms&lt;/strong&gt; group by field to let users switch between grouping by &lt;code&gt;hostname&lt;/code&gt;, &lt;code&gt;service&lt;/code&gt;, or &lt;code&gt;datacenter&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&#34;template-variable-examples&#34;&gt;Template variable examples&lt;/h2&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow&#34;
    style=&#34;max-width: 500px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link captioned&#34;
        href=&#34;/static/img/docs/elasticsearch/elastic-templating-query-7-4.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload mb-0&#34;
          data-src=&#34;/static/img/docs/elasticsearch/elastic-templating-query-7-4.png&#34;data-srcset=&#34;/static/img/docs/elasticsearch/elastic-templating-query-7-4.png?w=320 320w, /static/img/docs/elasticsearch/elastic-templating-query-7-4.png?w=550 550w, /static/img/docs/elasticsearch/elastic-templating-query-7-4.png?w=750 750w, /static/img/docs/elasticsearch/elastic-templating-query-7-4.png?w=900 900w, /static/img/docs/elasticsearch/elastic-templating-query-7-4.png?w=1040 1040w, /static/img/docs/elasticsearch/elastic-templating-query-7-4.png?w=1240 1240w, /static/img/docs/elasticsearch/elastic-templating-query-7-4.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;Query with template variables&#34;width=&#34;920&#34;height=&#34;190&#34;title=&#34;Query with template variables&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/elasticsearch/elastic-templating-query-7-4.png&#34;
            alt=&#34;Query with template variables&#34;width=&#34;920&#34;height=&#34;190&#34;title=&#34;Query with template variables&#34;class=&#34;docs-image--no-shadow&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;figcaption class=&#34;w-100p caption text-gray-13  &#34;&gt;Query with template variables&lt;/figcaption&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;In the above example, a Lucene query filters documents based on the &lt;code&gt;hostname&lt;/code&gt; property using a variable named &lt;code&gt;$hostname&lt;/code&gt;.
The example also uses a variable in the &lt;em&gt;Terms&lt;/em&gt; group by field input box, which you can use to quickly change how data is grouped.&lt;/p&gt;
&lt;h2 id=&#34;create-a-query&#34;&gt;Create a query&lt;/h2&gt;
&lt;p&gt;Write the query using a custom JSON string, with the field mapped as a &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html#keyword&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;keyword&lt;/a&gt; in the Elasticsearch index mapping.&lt;/p&gt;
&lt;p&gt;If the query is &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;multi-field&lt;/a&gt; with both a &lt;code&gt;text&lt;/code&gt; and &lt;code&gt;keyword&lt;/code&gt; type, use &lt;code&gt;&amp;quot;field&amp;quot;:&amp;quot;fieldname.keyword&amp;quot;&lt;/code&gt; (sometimes &lt;code&gt;fieldname.raw&lt;/code&gt;) to specify the keyword field in your query.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Query&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;{&amp;quot;find&amp;quot;: &amp;quot;fields&amp;quot;, &amp;quot;type&amp;quot;: &amp;quot;keyword&amp;quot;}&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Returns a list of field names with the index type &lt;code&gt;keyword&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;{&amp;quot;find&amp;quot;: &amp;quot;fields&amp;quot;, &amp;quot;type&amp;quot;: &amp;quot;number&amp;quot;}&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Returns a list of numeric field names (includes &lt;code&gt;float&lt;/code&gt;, &lt;code&gt;double&lt;/code&gt;, &lt;code&gt;integer&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;, &lt;code&gt;scaled_float&lt;/code&gt;).&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;{&amp;quot;find&amp;quot;: &amp;quot;fields&amp;quot;, &amp;quot;type&amp;quot;: &amp;quot;date&amp;quot;}&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Returns a list of date field names.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;{&amp;quot;find&amp;quot;: &amp;quot;terms&amp;quot;, &amp;quot;field&amp;quot;: &amp;quot;hostname.keyword&amp;quot;, &amp;quot;size&amp;quot;: 1000}&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Returns a list of values for a keyword field. Uses the current dashboard time range.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;{&amp;quot;find&amp;quot;: &amp;quot;terms&amp;quot;, &amp;quot;field&amp;quot;: &amp;quot;hostname&amp;quot;, &amp;quot;query&amp;quot;: &amp;quot;&amp;lt;Lucene query&amp;gt;&amp;quot;}&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Returns a list of values filtered by a Lucene query. Uses the current dashboard time range.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;{&amp;quot;find&amp;quot;: &amp;quot;terms&amp;quot;, &amp;quot;field&amp;quot;: &amp;quot;status&amp;quot;, &amp;quot;orderBy&amp;quot;: &amp;quot;doc_count&amp;quot;}&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Returns values sorted by document count (descending by default).&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;{&amp;quot;find&amp;quot;: &amp;quot;terms&amp;quot;, &amp;quot;field&amp;quot;: &amp;quot;status&amp;quot;, &amp;quot;orderBy&amp;quot;: &amp;quot;doc_count&amp;quot;, &amp;quot;order&amp;quot;: &amp;quot;asc&amp;quot;}&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Returns values sorted by document count in ascending order.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;Queries of &lt;code&gt;terms&lt;/code&gt; have a 500-result limit by default. To set a custom limit, set the &lt;code&gt;size&lt;/code&gt; property in your query.&lt;/p&gt;
&lt;h3 id=&#34;sort-query-results&#34;&gt;Sort query results&lt;/h3&gt;
&lt;p&gt;By default, queries return results in term order (which can then be sorted alphabetically or numerically using the variable&amp;rsquo;s Sort setting).&lt;/p&gt;
&lt;p&gt;To produce a list of terms sorted by document count (a top-N values list), add an &lt;code&gt;orderBy&lt;/code&gt; property of &lt;code&gt;doc_count&lt;/code&gt;. This automatically selects a descending sort:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JSON&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-json&#34;&gt;{ &amp;#34;find&amp;#34;: &amp;#34;terms&amp;#34;, &amp;#34;field&amp;#34;: &amp;#34;status&amp;#34;, &amp;#34;orderBy&amp;#34;: &amp;#34;doc_count&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can also use the &lt;code&gt;order&lt;/code&gt; property to explicitly set ascending or descending sort:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JSON&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-json&#34;&gt;{ &amp;#34;find&amp;#34;: &amp;#34;terms&amp;#34;, &amp;#34;field&amp;#34;: &amp;#34;hostname&amp;#34;, &amp;#34;orderBy&amp;#34;: &amp;#34;doc_count&amp;#34;, &amp;#34;order&amp;#34;: &amp;#34;asc&amp;#34; }&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Elasticsearch &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-order&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;discourages&lt;/a&gt; sorting by ascending doc count because it can return inaccurate results.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;To keep terms in the document count order, set the variable&amp;rsquo;s Sort drop-down to &lt;strong&gt;Disabled&lt;/strong&gt;. You can alternatively use other sorting criteria, such as &lt;strong&gt;Alphabetical&lt;/strong&gt;, to re-sort them.&lt;/p&gt;
]]></content><description>&lt;h1 id="elasticsearch-template-variables">Elasticsearch template variables&lt;/h1>
&lt;p>Instead of hard-coding details such as server, application, and sensor names in metric queries, you can use variables.
Grafana lists these variables in drop-down select boxes at the top of the dashboard to help you change the data displayed in your dashboard.
Grafana refers to such variables as template variables.&lt;/p></description></item><item><title>Elasticsearch annotations</title><link>https://grafana.com/docs/grafana/v12.4/datasources/elasticsearch/annotations/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/datasources/elasticsearch/annotations/</guid><content><![CDATA[&lt;h1 id=&#34;elasticsearch-annotations&#34;&gt;Elasticsearch annotations&lt;/h1&gt;
&lt;p&gt;Annotations overlay event data on your dashboard graphs, helping you correlate log events with metrics.
You can use Elasticsearch as a data source for annotations to display events such as deployments, alerts, or other significant occurrences on your visualizations.&lt;/p&gt;
&lt;p&gt;For general information about annotations, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/dashboards/build-dashboards/annotate-visualizations/&#34;&gt;Annotate visualizations&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;p&gt;Before creating Elasticsearch annotations, ensure you have:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;An Elasticsearch data source configured in Grafana&lt;/li&gt;
&lt;li&gt;Documents in Elasticsearch containing event data with timestamp fields&lt;/li&gt;
&lt;li&gt;Read access to the Elasticsearch index containing your events&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;create-an-annotation-query&#34;&gt;Create an annotation query&lt;/h2&gt;
&lt;p&gt;To add an Elasticsearch annotation to your dashboard:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Navigate to your dashboard and click &lt;strong&gt;Dashboard settings&lt;/strong&gt; (gear icon).&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Annotations&lt;/strong&gt; in the left menu.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Add annotation query&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Enter a &lt;strong&gt;Name&lt;/strong&gt; for the annotation.&lt;/li&gt;
&lt;li&gt;Select your &lt;strong&gt;Elasticsearch&lt;/strong&gt; data source from the &lt;strong&gt;Data source&lt;/strong&gt; drop-down.&lt;/li&gt;
&lt;li&gt;Configure the annotation query and field mappings.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Save dashboard&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;query&#34;&gt;Query&lt;/h2&gt;
&lt;p&gt;Use the query field to filter which Elasticsearch documents appear as annotations. The query uses &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-syntax&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Lucene query syntax&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Examples:&lt;/strong&gt;&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Query&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;*&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Matches all documents.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;type:deployment&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Shows only deployment events.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;level:error OR level:critical&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Shows error and critical events.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;service:api AND environment:production&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Shows events for a specific service and environment.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;tags:release&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Shows events tagged as releases.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;You can use template variables in your annotation queries. For example, &lt;code&gt;service:$service&lt;/code&gt; filters annotations based on the selected service variable.&lt;/p&gt;
&lt;h2 id=&#34;field-mappings&#34;&gt;Field mappings&lt;/h2&gt;
&lt;p&gt;Field mappings tell Grafana which Elasticsearch fields contain the annotation data.&lt;/p&gt;
&lt;h3 id=&#34;time&#34;&gt;Time&lt;/h3&gt;
&lt;p&gt;The &lt;strong&gt;Time&lt;/strong&gt; field specifies which field contains the annotation timestamp.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Default:&lt;/strong&gt; &lt;code&gt;@timestamp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Format:&lt;/strong&gt; The field must contain a date value that Elasticsearch recognizes.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;time-end&#34;&gt;Time End&lt;/h3&gt;
&lt;p&gt;The &lt;strong&gt;Time End&lt;/strong&gt; field specifies a field containing the end time for range annotations. Range annotations display as a shaded region on the graph instead of a single vertical line.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Default:&lt;/strong&gt; Empty (single-point annotations)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use case:&lt;/strong&gt; Display maintenance windows, incidents, or any event with a duration.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;text&#34;&gt;Text&lt;/h3&gt;
&lt;p&gt;The &lt;strong&gt;Text&lt;/strong&gt; field specifies which field contains the annotation description displayed when you hover over the annotation.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Default:&lt;/strong&gt; &lt;code&gt;tags&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tip:&lt;/strong&gt; Use a descriptive field like &lt;code&gt;message&lt;/code&gt;, &lt;code&gt;description&lt;/code&gt;, or &lt;code&gt;summary&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;tags&#34;&gt;Tags&lt;/h3&gt;
&lt;p&gt;The &lt;strong&gt;Tags&lt;/strong&gt; field specifies which field contains tags for the annotation. Tags help categorize and filter annotations.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Default:&lt;/strong&gt; Empty&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Format:&lt;/strong&gt; The field can contain either a comma-separated string or an array of strings.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;example-deployment-annotations&#34;&gt;Example: Deployment annotations&lt;/h2&gt;
&lt;p&gt;To display deployment events as annotations:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create an annotation query with the following settings:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Query:&lt;/strong&gt; &lt;code&gt;type:deployment&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Time:&lt;/strong&gt; &lt;code&gt;@timestamp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Text:&lt;/strong&gt; &lt;code&gt;message&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tags:&lt;/strong&gt; &lt;code&gt;environment&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This configuration displays deployment events with their messages as the annotation text and environments as tags.&lt;/p&gt;
&lt;h2 id=&#34;example-range-annotations-for-incidents&#34;&gt;Example: Range annotations for incidents&lt;/h2&gt;
&lt;p&gt;To display incidents with duration:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create an annotation query with the following settings:
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Query:&lt;/strong&gt; &lt;code&gt;type:incident&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Time:&lt;/strong&gt; &lt;code&gt;start_time&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Time End:&lt;/strong&gt; &lt;code&gt;end_time&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Text:&lt;/strong&gt; &lt;code&gt;description&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tags:&lt;/strong&gt; &lt;code&gt;severity&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This configuration displays incidents as shaded regions from their start time to end time.&lt;/p&gt;
]]></content><description>&lt;h1 id="elasticsearch-annotations">Elasticsearch annotations&lt;/h1>
&lt;p>Annotations overlay event data on your dashboard graphs, helping you correlate log events with metrics.
You can use Elasticsearch as a data source for annotations to display events such as deployments, alerts, or other significant occurrences on your visualizations.&lt;/p></description></item><item><title>Elasticsearch alerting</title><link>https://grafana.com/docs/grafana/v12.4/datasources/elasticsearch/alerting/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/datasources/elasticsearch/alerting/</guid><content><![CDATA[&lt;h1 id=&#34;elasticsearch-alerting&#34;&gt;Elasticsearch alerting&lt;/h1&gt;
&lt;p&gt;You can use Grafana Alerting with Elasticsearch to create alerts based on your Elasticsearch data. This allows you to monitor metrics, detect anomalies, and receive notifications when specific conditions are met.&lt;/p&gt;
&lt;p&gt;For general information about Grafana Alerting, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/alerting/&#34;&gt;Grafana Alerting&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;p&gt;Before creating alerts with Elasticsearch, ensure you have:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;An Elasticsearch data source configured in Grafana&lt;/li&gt;
&lt;li&gt;Appropriate permissions to create alert rules&lt;/li&gt;
&lt;li&gt;Understanding of the metrics you want to monitor&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;supported-query-types&#34;&gt;Supported query types&lt;/h2&gt;
&lt;p&gt;Elasticsearch alerting works best with &lt;strong&gt;metrics queries&lt;/strong&gt; that return time series data. To create a valid alert query:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Use a &lt;strong&gt;Date histogram&lt;/strong&gt; as the last bucket aggregation (under &lt;strong&gt;Group by&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;Select appropriate metric aggregations (Count, Average, Sum, Min, Max, etc.)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Queries that return time series data allow Grafana to evaluate values over time and trigger alerts when thresholds are crossed.&lt;/p&gt;
&lt;h3 id=&#34;query-types-and-alerting-compatibility&#34;&gt;Query types and alerting compatibility&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Query type&lt;/th&gt;
              &lt;th&gt;Alerting support&lt;/th&gt;
              &lt;th&gt;Notes&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Metrics with Date histogram&lt;/td&gt;
              &lt;td&gt;✅ Full support&lt;/td&gt;
              &lt;td&gt;Recommended for alerting&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Metrics without Date histogram&lt;/td&gt;
              &lt;td&gt;⚠️ Limited&lt;/td&gt;
              &lt;td&gt;May not evaluate correctly over time&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Logs&lt;/td&gt;
              &lt;td&gt;❌ Not supported&lt;/td&gt;
              &lt;td&gt;Use metrics queries instead&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Raw data&lt;/td&gt;
              &lt;td&gt;❌ Not supported&lt;/td&gt;
              &lt;td&gt;Use metrics queries instead&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Raw document (deprecated)&lt;/td&gt;
              &lt;td&gt;❌ Not supported&lt;/td&gt;
              &lt;td&gt;Deprecated since Grafana v10.1. Use metrics queries instead&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;create-an-alert-rule&#34;&gt;Create an alert rule&lt;/h2&gt;
&lt;p&gt;To create an alert rule using Elasticsearch:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Navigate to &lt;strong&gt;Alerting&lt;/strong&gt; &amp;gt; &lt;strong&gt;Alert rules&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;New alert rule&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Enter a name for the alert rule.&lt;/li&gt;
&lt;li&gt;Select your &lt;strong&gt;Elasticsearch&lt;/strong&gt; data source.&lt;/li&gt;
&lt;li&gt;Build your query using the query editor:
&lt;ul&gt;
&lt;li&gt;Add metric aggregations (for example, Average, Count, Sum)&lt;/li&gt;
&lt;li&gt;Add a Date histogram under &lt;strong&gt;Group by&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Optionally add filters using Lucene query syntax&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Configure the alert condition (for example, when the average is above a threshold).&lt;/li&gt;
&lt;li&gt;Set the evaluation interval and pending period.&lt;/li&gt;
&lt;li&gt;Configure notifications and labels.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Save rule&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For detailed instructions, refer to 
    &lt;a href=&#34;/docs/grafana/v12.4/alerting/alerting-rules/create-grafana-managed-rule/&#34;&gt;Create a Grafana-managed alert rule&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;example-alert-queries&#34;&gt;Example alert queries&lt;/h2&gt;
&lt;p&gt;The following examples show common alerting scenarios with Elasticsearch.&lt;/p&gt;
&lt;h3 id=&#34;alert-on-high-error-count&#34;&gt;Alert on high error count&lt;/h3&gt;
&lt;p&gt;Monitor the number of error-level log entries:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Query:&lt;/strong&gt; &lt;code&gt;level:error&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Metric:&lt;/strong&gt; Count&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Group by:&lt;/strong&gt; Date histogram (interval: 1m)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Condition:&lt;/strong&gt; When count is above 100&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;alert-on-average-response-time&#34;&gt;Alert on average response time&lt;/h3&gt;
&lt;p&gt;Monitor API response times:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Query:&lt;/strong&gt; &lt;code&gt;type:api_request&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Metric:&lt;/strong&gt; Average on field &lt;code&gt;response_time&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Group by:&lt;/strong&gt; Date histogram (interval: 5m)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Condition:&lt;/strong&gt; When average is above 500 (milliseconds)&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;alert-on-unique-user-count-drop&#34;&gt;Alert on unique user count drop&lt;/h3&gt;
&lt;p&gt;Detect drops in active users:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Query:&lt;/strong&gt; &lt;code&gt;*&lt;/code&gt; (all documents)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Metric:&lt;/strong&gt; Unique count on field &lt;code&gt;user_id&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Group by:&lt;/strong&gt; Date histogram (interval: 1h)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Condition:&lt;/strong&gt; When unique count is below 100&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;limitations&#34;&gt;Limitations&lt;/h2&gt;
&lt;p&gt;When using Elasticsearch with Grafana Alerting, be aware of the following limitations:&lt;/p&gt;
&lt;h3 id=&#34;template-variables-not-supported&#34;&gt;Template variables not supported&lt;/h3&gt;
&lt;p&gt;Alert queries cannot contain template variables. Grafana evaluates alert rules on the backend without dashboard context, so variables like &lt;code&gt;$hostname&lt;/code&gt; or &lt;code&gt;$environment&lt;/code&gt; won&amp;rsquo;t be resolved.&lt;/p&gt;
&lt;p&gt;If your dashboard query uses template variables, create a separate query for alerting with hard coded values.&lt;/p&gt;
&lt;h3 id=&#34;logs-queries-not-supported&#34;&gt;Logs queries not supported&lt;/h3&gt;
&lt;p&gt;Queries using the &lt;strong&gt;Logs&lt;/strong&gt; metric type cannot be used for alerting. Convert your query to use metric aggregations with a Date histogram instead.&lt;/p&gt;
&lt;h3 id=&#34;query-complexity&#34;&gt;Query complexity&lt;/h3&gt;
&lt;p&gt;Complex queries with many nested aggregations may timeout or fail to evaluate. Simplify queries for alerting by:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Reducing the number of bucket aggregations&lt;/li&gt;
&lt;li&gt;Using appropriate time intervals&lt;/li&gt;
&lt;li&gt;Adding filters to limit the data scanned&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;best-practices&#34;&gt;Best practices&lt;/h2&gt;
&lt;p&gt;Follow these best practices when creating Elasticsearch alerts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Use specific filters:&lt;/strong&gt; Add Lucene query filters to focus on relevant data and improve query performance.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Choose appropriate intervals:&lt;/strong&gt; Match the Date histogram interval to your evaluation frequency.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test queries first:&lt;/strong&gt; Verify your query returns expected results in Explore before creating an alert.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Set realistic thresholds:&lt;/strong&gt; Base alert thresholds on historical data patterns.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use meaningful names:&lt;/strong&gt; Give alert rules descriptive names that indicate what they monitor.&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="elasticsearch-alerting">Elasticsearch alerting&lt;/h1>
&lt;p>You can use Grafana Alerting with Elasticsearch to create alerts based on your Elasticsearch data. This allows you to monitor metrics, detect anomalies, and receive notifications when specific conditions are met.&lt;/p></description></item><item><title>Troubleshoot issues with the Elasticsearch data source</title><link>https://grafana.com/docs/grafana/v12.4/datasources/elasticsearch/troubleshooting/</link><pubDate>Fri, 03 Apr 2026 19:43:06 +0000</pubDate><guid>https://grafana.com/docs/grafana/v12.4/datasources/elasticsearch/troubleshooting/</guid><content><![CDATA[&lt;h1 id=&#34;troubleshoot-issues-with-the-elasticsearch-data-source&#34;&gt;Troubleshoot issues with the Elasticsearch data source&lt;/h1&gt;
&lt;p&gt;This document provides troubleshooting information for common errors you may encounter when using the Elasticsearch data source in Grafana.&lt;/p&gt;
&lt;h2 id=&#34;connection-errors&#34;&gt;Connection errors&lt;/h2&gt;
&lt;p&gt;The following errors occur when Grafana cannot establish or maintain a connection to Elasticsearch.&lt;/p&gt;
&lt;h3 id=&#34;failed-to-connect-to-elasticsearch&#34;&gt;Failed to connect to Elasticsearch&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Health check failed: Failed to connect to Elasticsearch&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Grafana cannot establish a network connection to the Elasticsearch server.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify that the Elasticsearch URL is correct in the data source configuration.&lt;/li&gt;
&lt;li&gt;Check that Elasticsearch is running and accessible from the Grafana server.&lt;/li&gt;
&lt;li&gt;Ensure there are no firewall rules blocking the connection.&lt;/li&gt;
&lt;li&gt;If using a proxy, verify the proxy settings are correct.&lt;/li&gt;
&lt;li&gt;For Grafana Cloud, ensure you have configured &lt;a href=&#34;/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/&#34;&gt;Private data source connect&lt;/a&gt; if your Elasticsearch instance is not publicly accessible.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;request-timed-out&#34;&gt;Request timed out&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Health check failed: Elasticsearch data source is not healthy. Request timed out&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The connection to Elasticsearch timed out before receiving a response.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check the network latency between Grafana and Elasticsearch.&lt;/li&gt;
&lt;li&gt;Verify that Elasticsearch is not overloaded or experiencing performance issues.&lt;/li&gt;
&lt;li&gt;Increase the timeout setting in the data source configuration if needed.&lt;/li&gt;
&lt;li&gt;Check if any network devices (load balancers, proxies) are timing out the connection.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;failed-to-parse-data-source-url&#34;&gt;Failed to parse data source URL&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Failed to parse data source URL&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The URL entered in the data source configuration is not valid.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify the URL format is correct (for example, &lt;code&gt;http://localhost:9200&lt;/code&gt; or &lt;code&gt;https://elasticsearch.example.com:9200&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Ensure the URL includes the protocol (&lt;code&gt;http://&lt;/code&gt; or &lt;code&gt;https://&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Remove any trailing slashes or invalid characters from the URL.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;authentication-errors&#34;&gt;Authentication errors&lt;/h2&gt;
&lt;p&gt;The following errors occur when there are issues with authentication credentials or permissions.&lt;/p&gt;
&lt;h3 id=&#34;unauthorized-401&#34;&gt;Unauthorized (401)&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Health check failed: Elasticsearch data source is not healthy. Status: 401 Unauthorized&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The authentication credentials are invalid or missing.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify that the username and password are correct.&lt;/li&gt;
&lt;li&gt;If using an API key, ensure the key is valid and has not expired.&lt;/li&gt;
&lt;li&gt;Check that the authentication method selected matches your Elasticsearch configuration.&lt;/li&gt;
&lt;li&gt;Verify the user has the required permissions to access the Elasticsearch cluster.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;forbidden-403&#34;&gt;Forbidden (403)&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Health check failed: Elasticsearch data source is not healthy. Status: 403 Forbidden&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The authenticated user does not have permission to access the requested resource.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify the user has read access to the specified index.&lt;/li&gt;
&lt;li&gt;Check Elasticsearch security settings and role mappings.&lt;/li&gt;
&lt;li&gt;Ensure the user has permission to access the &lt;code&gt;_cluster/health&lt;/code&gt; endpoint.&lt;/li&gt;
&lt;li&gt;If using AWS Elasticsearch Service with SigV4 authentication, verify the IAM policy grants the required permissions.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;cluster-health-errors&#34;&gt;Cluster health errors&lt;/h2&gt;
&lt;p&gt;The following errors occur when the Elasticsearch cluster is unhealthy or unavailable.&lt;/p&gt;
&lt;h3 id=&#34;cluster-status-is-red&#34;&gt;Cluster status is red&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Health check failed: Elasticsearch data source is not healthy&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The Elasticsearch cluster health status is red, indicating one or more primary shards are not allocated.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check the Elasticsearch cluster health using &lt;code&gt;GET /_cluster/health&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Review Elasticsearch logs for errors.&lt;/li&gt;
&lt;li&gt;Verify all nodes in the cluster are running and connected.&lt;/li&gt;
&lt;li&gt;Check for unassigned shards using &lt;code&gt;GET /_cat/shards?v&amp;amp;h=index,shard,prirep,state,unassigned.reason&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Consider increasing the cluster&amp;rsquo;s resources or reducing the number of shards.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;bad-gateway-502&#34;&gt;Bad Gateway (502)&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Health check failed: Elasticsearch data source is not healthy. Status: 502 Bad Gateway&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; A proxy or load balancer between Grafana and Elasticsearch returned an error.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check the health of any proxies or load balancers in the connection path.&lt;/li&gt;
&lt;li&gt;Verify Elasticsearch is running and accepting connections.&lt;/li&gt;
&lt;li&gt;Review proxy/load balancer logs for more details.&lt;/li&gt;
&lt;li&gt;Ensure the proxy timeout is configured appropriately for Elasticsearch requests.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;index-errors&#34;&gt;Index errors&lt;/h2&gt;
&lt;p&gt;The following errors occur when there are issues with the configured index or index pattern.&lt;/p&gt;
&lt;h3 id=&#34;index-not-found&#34;&gt;Index not found&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Error validating index: index_not_found&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The specified index or index pattern does not match any existing indices.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify the index name or pattern in the data source configuration.&lt;/li&gt;
&lt;li&gt;Check that the index exists using &lt;code&gt;GET /_cat/indices&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If using a time-based index pattern (for example, &lt;code&gt;[logs-]YYYY.MM.DD&lt;/code&gt;), ensure indices exist for the selected time range.&lt;/li&gt;
&lt;li&gt;Verify the user has permission to access the index.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;time-field-not-found&#34;&gt;Time field not found&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Could not find time field &amp;lsquo;@timestamp&amp;rsquo; with type date in index&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The specified time field does not exist in the index or is not of type &lt;code&gt;date&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify the time field name in the data source configuration matches the field in your index.&lt;/li&gt;
&lt;li&gt;Check the field mapping using &lt;code&gt;GET /&amp;lt;index&amp;gt;/_mapping&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Ensure the time field is mapped as a &lt;code&gt;date&lt;/code&gt; type, not &lt;code&gt;text&lt;/code&gt; or &lt;code&gt;keyword&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If the field name is different (for example, &lt;code&gt;timestamp&lt;/code&gt; instead of &lt;code&gt;@timestamp&lt;/code&gt;), update the data source configuration.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;query-errors&#34;&gt;Query errors&lt;/h2&gt;
&lt;p&gt;The following errors occur when there are issues with query syntax or configuration.&lt;/p&gt;
&lt;h3 id=&#34;too-many-buckets&#34;&gt;Too many buckets&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Trying to create too many buckets. Must be less than or equal to: [65536].&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The query is generating more aggregation buckets than Elasticsearch allows.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Reduce the time range of your query.&lt;/li&gt;
&lt;li&gt;Increase the date histogram interval (for example, change from &lt;code&gt;10s&lt;/code&gt; to &lt;code&gt;1m&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Add filters to reduce the number of documents being aggregated.&lt;/li&gt;
&lt;li&gt;Increase the &lt;code&gt;search.max_buckets&lt;/code&gt; setting in Elasticsearch (requires cluster admin access).&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;required-field-missing&#34;&gt;Required field missing&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Required one of fields [field, script], but none were specified.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; A metric aggregation (such as Average, Sum, or Min) was added without specifying a field.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Select a field for the metric aggregation in the query editor.&lt;/li&gt;
&lt;li&gt;Ensure the selected field exists in your index and contains numeric data.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;unsupported-interval&#34;&gt;Unsupported interval&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;unsupported interval &amp;lsquo;&amp;lt;interval&amp;gt;&amp;rsquo;&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The interval specified for the index pattern is not valid.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use a supported interval: &lt;code&gt;Hourly&lt;/code&gt;, &lt;code&gt;Daily&lt;/code&gt;, &lt;code&gt;Weekly&lt;/code&gt;, &lt;code&gt;Monthly&lt;/code&gt;, or &lt;code&gt;Yearly&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;If you don&amp;rsquo;t need a time-based index pattern, use &lt;code&gt;No pattern&lt;/code&gt; and specify the exact index name.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;version-errors&#34;&gt;Version errors&lt;/h2&gt;
&lt;p&gt;The following errors occur when there are Elasticsearch version compatibility issues.&lt;/p&gt;
&lt;h3 id=&#34;unsupported-elasticsearch-version&#34;&gt;Unsupported Elasticsearch version&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Support for Elasticsearch versions after their end-of-life (currently versions &amp;lt; 7.16) was removed. Using unsupported version of Elasticsearch may lead to unexpected and incorrect results.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The Elasticsearch version is no longer supported by the Grafana data source.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Upgrade Elasticsearch to a supported version (7.17&#43;, 8.x, or 9.x).&lt;/li&gt;
&lt;li&gt;Refer to &lt;a href=&#34;https://www.elastic.co/support/eol&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Elastic Product End of Life Dates&lt;/a&gt; for version support information.&lt;/li&gt;
&lt;li&gt;Note that queries may still work, but Grafana does not guarantee functionality for unsupported versions.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;other-common-issues&#34;&gt;Other common issues&lt;/h2&gt;
&lt;p&gt;The following issues don&amp;rsquo;t produce specific error messages but are commonly encountered.&lt;/p&gt;
&lt;h3 id=&#34;empty-query-results&#34;&gt;Empty query results&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The query returns no data.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify the time range includes data in your index.&lt;/li&gt;
&lt;li&gt;Check the Lucene query syntax for errors.&lt;/li&gt;
&lt;li&gt;Test the query directly in Elasticsearch using the &lt;code&gt;_search&lt;/code&gt; API.&lt;/li&gt;
&lt;li&gt;Ensure the index contains documents matching your query filters.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;slow-query-performance&#34;&gt;Slow query performance&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Queries take a long time to execute.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Reduce the time range of your query.&lt;/li&gt;
&lt;li&gt;Add more specific filters to limit the data scanned.&lt;/li&gt;
&lt;li&gt;Increase the date histogram interval.&lt;/li&gt;
&lt;li&gt;Check Elasticsearch cluster performance and resource utilization.&lt;/li&gt;
&lt;li&gt;Consider using index aliases or data streams for better query routing.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;cors-errors-in-browser-console&#34;&gt;CORS errors in browser console&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Cross-Origin Resource Sharing (CORS) is blocking requests from the browser to Elasticsearch.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use Server (proxy) access mode instead of Browser access mode in the data source configuration.&lt;/li&gt;
&lt;li&gt;If Browser access is required, configure CORS settings in Elasticsearch:&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;http.cors.enabled: true
http.cors.allow-origin: &amp;#39;&amp;lt;your-grafana-url&amp;gt;&amp;#39;
http.cors.allow-headers: &amp;#39;Authorization, Content-Type&amp;#39;
http.cors.allow-credentials: true&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Server (proxy) access mode is recommended for security and reliability.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;get-additional-help&#34;&gt;Get additional help&lt;/h2&gt;
&lt;p&gt;If you continue to experience issues after following this troubleshooting guide:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check the &lt;a href=&#34;https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Elasticsearch documentation&lt;/a&gt; for API-specific guidance.&lt;/li&gt;
&lt;li&gt;Review the &lt;a href=&#34;https://community.grafana.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana community forums&lt;/a&gt; for similar issues.&lt;/li&gt;
&lt;li&gt;Contact Grafana Support if you have an Enterprise license.&lt;/li&gt;
&lt;/ol&gt;
]]></content><description>&lt;h1 id="troubleshoot-issues-with-the-elasticsearch-data-source">Troubleshoot issues with the Elasticsearch data source&lt;/h1>
&lt;p>This document provides troubleshooting information for common errors you may encounter when using the Elasticsearch data source in Grafana.&lt;/p></description></item></channel></rss>