diff --git a/pkg/tsdb/elasticsearch/client/client.go b/pkg/tsdb/elasticsearch/client/client.go index 226bb5a0091..ccdd3c7fe8d 100644 --- a/pkg/tsdb/elasticsearch/client/client.go +++ b/pkg/tsdb/elasticsearch/client/client.go @@ -184,7 +184,7 @@ func (c *baseClientImpl) executeRequest(method, uriPath, uriQuery string, body [ } req.Header.Set("User-Agent", "Grafana") - req.Header.Set("Content-Type", "application/json") + req.Header.Set("Content-Type", "application/x-ndjson") if c.ds.BasicAuth { clientLog.Debug("Request configured to use basic authentication") diff --git a/pkg/tsdb/elasticsearch/client/client_test.go b/pkg/tsdb/elasticsearch/client/client_test.go index e20e523e17a..76d0c295152 100644 --- a/pkg/tsdb/elasticsearch/client/client_test.go +++ b/pkg/tsdb/elasticsearch/client/client_test.go @@ -366,7 +366,7 @@ func httpClientScenario(t *testing.T, desc string, ds *models.DataSource, fn sce sc.requestBody = bytes.NewBuffer(buf) - rw.Header().Set("Content-Type", "application/json") + rw.Header().Set("Content-Type", "application/x-ndjson") _, err = rw.Write([]byte(sc.responseBody)) require.NoError(t, err) rw.WriteHeader(sc.responseStatus) diff --git a/public/app/plugins/datasource/elasticsearch/datasource.ts b/public/app/plugins/datasource/elasticsearch/datasource.ts index 7ac4d57fe7d..634816cecb9 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.ts +++ b/public/app/plugins/datasource/elasticsearch/datasource.ts @@ -23,7 +23,7 @@ import { ElasticResponse } from './elastic_response'; import { IndexPattern } from './index_pattern'; import { ElasticQueryBuilder } from './query_builder'; import { defaultBucketAgg, hasMetricOfType } from './query_def'; -import { getBackendSrv, getDataSourceSrv } from '@grafana/runtime'; +import { BackendSrvRequest, getBackendSrv, getDataSourceSrv } from '@grafana/runtime'; import { getTemplateSrv, TemplateSrv } from 'app/features/templating/template_srv'; import { DataLinkConfig, ElasticsearchOptions, ElasticsearchQuery } from './types'; import { RowContextOptions } from '@grafana/ui/src/components/Logs/LogRowContextProvider'; @@ -104,11 +104,17 @@ export class ElasticDatasource extends DataSourceApi { - const options: any = { + private request( + method: string, + url: string, + data?: undefined, + headers?: BackendSrvRequest['headers'] + ): Observable { + const options: BackendSrvRequest = { url: this.url + '/' + url, - method: method, - data: data, + method, + data, + headers, }; if (this.basicAuth || this.withCredentials) { @@ -192,7 +198,7 @@ export class ElasticDatasource extends DataSourceApi { - return this.request('POST', url, data); + return this.request('POST', url, data, { 'Content-Type': 'application/x-ndjson' }); } annotationQuery(options: any): Promise {