Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
e4950c2d
Commit
e4950c2d
authored
Jul 12, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: elasticsearch with template variable with terms agg on IP field, fixes #8662
parent
4844bf9b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
11 deletions
+35
-11
public/app/plugins/datasource/elasticsearch/datasource.js
+7
-6
public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts
+28
-5
No files found.
public/app/plugins/datasource/elasticsearch/datasource.js
View file @
e4950c2d
...
...
@@ -323,26 +323,27 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
var
buckets
=
res
.
responses
[
0
].
aggregations
[
"1"
].
buckets
;
return
_
.
map
(
buckets
,
function
(
bucket
)
{
return
{
text
:
bucket
.
key
,
value
:
bucket
.
key
};
return
{
text
:
bucket
.
key_as_string
||
bucket
.
key
,
value
:
bucket
.
key
};
});
});
};
this
.
metricFindQuery
=
function
(
query
)
{
query
=
angular
.
fromJson
(
query
);
query
.
query
=
templateSrv
.
replace
(
query
.
query
||
'*'
,
{},
'lucene'
);
if
(
'field'
in
query
)
{
query
.
field
=
templateSrv
.
replace
(
query
.
field
,
{},
'lucene'
);
}
if
(
!
query
)
{
return
$q
.
when
([]);
}
if
(
query
.
find
===
'fields'
)
{
query
.
field
=
templateSrv
.
replace
(
query
.
field
,
{},
'lucene'
);
return
this
.
getFields
(
query
);
}
if
(
query
.
find
===
'terms'
)
{
query
.
query
=
templateSrv
.
replace
(
query
.
query
||
'*'
,
{},
'lucene'
);
return
this
.
getTerms
(
query
);
}
};
...
...
public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts
View file @
e4950c2d
...
...
@@ -248,7 +248,7 @@ describe('ElasticDatasource', function() {
});
describe
(
'When issuing metricFind query on es5.x'
,
function
()
{
var
requestOptions
,
parts
,
header
,
body
;
var
requestOptions
,
parts
,
header
,
body
,
results
;
beforeEach
(
function
()
{
createDatasource
({
url
:
'http://es.com'
,
index
:
'test'
,
jsonData
:
{
esVersion
:
'5'
}});
...
...
@@ -256,13 +256,27 @@ describe('ElasticDatasource', function() {
ctx
.
backendSrv
.
datasourceRequest
=
function
(
options
)
{
requestOptions
=
options
;
return
ctx
.
$q
.
when
({
data
:
{
responses
:
[{
aggregations
:
{
"1"
:
[{
buckets
:
{
text
:
'test'
,
value
:
'1'
}}]}}]
}
data
:
{
responses
:
[
{
aggregations
:
{
"1"
:
{
buckets
:
[
{
doc_count
:
1
,
key
:
'test'
},
{
doc_count
:
2
,
key
:
'test2'
,
key_as_string
:
'test2_as_string'
},
]
}
}
}
]
}
});
};
ctx
.
ds
.
metricFindQuery
(
'{"find": "terms", "field": "test"}'
);
ctx
.
ds
.
metricFindQuery
(
'{"find": "terms", "field": "test"}'
).
then
(
res
=>
{
results
=
res
;
});
ctx
.
$rootScope
.
$apply
();
parts
=
requestOptions
.
data
.
split
(
'
\
n'
);
...
...
@@ -270,6 +284,15 @@ describe('ElasticDatasource', function() {
body
=
angular
.
fromJson
(
parts
[
1
]);
});
it
(
'should get results'
,
function
()
{
expect
(
results
.
length
).
to
.
eql
(
2
);
});
it
(
'should use key or key_as_string'
,
function
()
{
expect
(
results
[
0
].
text
).
to
.
eql
(
'test'
);
expect
(
results
[
1
].
text
).
to
.
eql
(
'test2_as_string'
);
});
it
(
'should not set search type to count'
,
function
()
{
expect
(
header
.
search_type
).
to
.
not
.
eql
(
'count'
);
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment