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
873024b9
Commit
873024b9
authored
Dec 06, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tech(elastic): use bool conditions for all es queries
parent
6440d884
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
59 additions
and
102 deletions
+59
-102
docker/blocks/elastic1/elasticsearch.yml
+2
-0
docker/blocks/elastic1/fig
+8
-0
docker/blocks/elastic5/fig
+2
-2
public/app/plugins/datasource/elasticsearch/datasource.js
+10
-1
public/app/plugins/datasource/elasticsearch/query_builder.js
+32
-93
public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts
+1
-1
public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts
+4
-5
No files found.
docker/blocks/elastic1/elasticsearch.yml
0 → 100644
View file @
873024b9
script.inline
:
on
script.indexed
:
on
docker/blocks/elastic1/fig
0 → 100644
View file @
873024b9
elasticsearch1:
image: elasticsearch:1.7.6
command: elasticsearch -Des.network.host=0.0.0.0
ports:
- "11200:9200"
- "11300:9300"
volumes:
- ./blocks/elastic/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
docker/blocks/elastic5/fig
View file @
873024b9
...
...
@@ -4,5 +4,5 @@ elasticsearch5:
image: elasticsearch:5
command: elasticsearch
ports:
- "
9
200:9200"
- "
9
300:9300"
- "
10
200:9200"
- "
10
300:9300"
public/app/plugins/datasource/elasticsearch/datasource.js
View file @
873024b9
...
...
@@ -88,7 +88,16 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
}
var
queryInterpolated
=
templateSrv
.
replace
(
queryString
,
{},
'lucene'
);
var
query
=
{
"bool"
:
{
"must"
:
[{
"range"
:
range
},
{
"query_string"
:
{
"query"
:
queryInterpolated
}
}]
}};
var
query
=
{
"bool"
:
{
"must"
:
[
{
"range"
:
range
},
{
"query_string"
:
{
"query"
:
queryInterpolated
}
}
]
}
};
var
data
=
{
"query"
:
query
,
...
...
public/app/plugins/datasource/elasticsearch/query_builder.js
View file @
873024b9
...
...
@@ -76,23 +76,13 @@ function (queryDef) {
for
(
var
i
=
0
;
i
<
aggDef
.
settings
.
filters
.
length
;
i
++
)
{
var
query
=
aggDef
.
settings
.
filters
[
i
].
query
;
if
(
this
.
esVersion
>=
5
)
{
filterObj
[
query
]
=
{
query_string
:
{
query
:
query
,
analyze_wildcard
:
true
}
};
}
else
{
filterObj
[
query
]
=
{
query
:
{
query_string
:
{
query
:
query
,
analyze_wildcard
:
true
}
}
};
}
filterObj
[
query
]
=
{
query_string
:
{
query
:
query
,
analyze_wildcard
:
true
}
};
}
return
filterObj
;
...
...
@@ -119,12 +109,7 @@ function (queryDef) {
}
var
i
,
filter
,
condition
,
must
;
if
(
this
.
esVersion
>=
5
)
{
must
=
query
.
query
.
bool
.
must
;
}
else
{
must
=
query
.
query
.
filtered
.
filter
.
bool
.
must
;
}
must
=
query
.
query
.
bool
.
must
;
for
(
i
=
0
;
i
<
adhocFilters
.
length
;
i
++
)
{
filter
=
adhocFilters
[
i
];
...
...
@@ -143,42 +128,21 @@ function (queryDef) {
var
i
,
nestedAggs
,
metric
;
var
query
=
{};
if
(
this
.
esVersion
>=
5
)
{
query
=
{
"size"
:
0
,
"query"
:
{
"bool"
:
{
"must"
:
[
{
"range"
:
this
.
getRangeFilter
()},
{
"query_string"
:
{
"analyze_wildcard"
:
true
,
"query"
:
'$lucene_query'
}
}
]
}
}
};
}
else
{
query
=
{
"size"
:
0
,
"query"
:
{
"filtered"
:
{
"query"
:
{
"query_string"
:
{
"analyze_wildcard"
:
true
,
"query"
:
'$lucene_query'
,
}
},
"filter"
:
{
"bool"
:
{
"must"
:
[{
"range"
:
this
.
getRangeFilter
()}]
query
=
{
"size"
:
0
,
"query"
:
{
"bool"
:
{
"must"
:
[
{
"range"
:
this
.
getRangeFilter
()},
{
"query_string"
:
{
"analyze_wildcard"
:
true
,
"query"
:
'$lucene_query'
}
}
}
]
}
}
;
}
}
}
;
this
.
addAdhocFilters
(
query
,
adhocFilters
);
...
...
@@ -258,47 +222,22 @@ function (queryDef) {
ElasticQueryBuilder
.
prototype
.
getTermsQuery
=
function
(
queryDef
)
{
var
query
;
if
(
this
.
esVersion
>=
5
)
{
query
=
{
"size"
:
0
,
"query"
:
{
"bool"
:
{
"must"
:
[{
"range"
:
this
.
getRangeFilter
()}]
}
query
=
{
"size"
:
0
,
"query"
:
{
"bool"
:
{
"must"
:
[{
"range"
:
this
.
getRangeFilter
()}]
}
};
if
(
queryDef
.
query
)
{
query
.
query
.
bool
.
must
.
push
({
"query_string"
:
{
"analyze_wildcard"
:
true
,
"query"
:
queryDef
.
query
,
}
});
}
};
}
else
{
query
=
{
"size"
:
0
,
"query"
:
{
"filtered"
:
{
"filter"
:
{
"bool"
:
{
"must"
:
[{
"range"
:
this
.
getRangeFilter
()}]
}
}
}
if
(
queryDef
.
query
)
{
query
.
query
.
bool
.
must
.
push
({
"query_string"
:
{
"analyze_wildcard"
:
true
,
"query"
:
queryDef
.
query
,
}
};
if
(
queryDef
.
query
)
{
query
.
query
.
filtered
.
query
=
{
"query_string"
:
{
"analyze_wildcard"
:
true
,
"query"
:
queryDef
.
query
,
}
};
}
});
}
query
.
aggs
=
{
...
...
public/app/plugins/datasource/elasticsearch/specs/datasource_specs.ts
View file @
873024b9
...
...
@@ -77,7 +77,7 @@ describe('ElasticDatasource', function() {
it
(
'should json escape lucene query'
,
function
()
{
var
body
=
angular
.
fromJson
(
parts
[
1
]);
expect
(
body
.
query
.
filtered
.
query
.
query_string
.
query
).
to
.
be
(
'escape
\\
:test'
);
expect
(
body
.
query
.
bool
.
must
[
1
]
.
query_string
.
query
).
to
.
be
(
'escape
\\
:test'
);
});
});
...
...
public/app/plugins/datasource/elasticsearch/specs/query_builder_specs.ts
View file @
873024b9
...
...
@@ -16,7 +16,7 @@ describe('ElasticQueryBuilder', function() {
bucketAggs
:
[{
type
:
'date_histogram'
,
field
:
'@timestamp'
,
id
:
'1'
}],
});
expect
(
query
.
query
.
filtered
.
filter
.
bool
.
must
[
0
].
range
[
"@timestamp"
].
gte
).
to
.
be
(
"$timeFrom"
);
expect
(
query
.
query
.
bool
.
must
[
0
].
range
[
"@timestamp"
].
gte
).
to
.
be
(
"$timeFrom"
);
expect
(
query
.
aggs
[
"1"
].
date_histogram
.
extended_bounds
.
min
).
to
.
be
(
"$timeFrom"
);
});
...
...
@@ -154,8 +154,8 @@ describe('ElasticQueryBuilder', function() {
],
});
expect
(
query
.
aggs
[
"2"
].
filters
.
filters
[
"@metric:cpu"
].
query
.
query
_string
.
query
).
to
.
be
(
"@metric:cpu"
);
expect
(
query
.
aggs
[
"2"
].
filters
.
filters
[
"@metric:logins.count"
].
query
.
query
_string
.
query
).
to
.
be
(
"@metric:logins.count"
);
expect
(
query
.
aggs
[
"2"
].
filters
.
filters
[
"@metric:cpu"
].
query_string
.
query
).
to
.
be
(
"@metric:cpu"
);
expect
(
query
.
aggs
[
"2"
].
filters
.
filters
[
"@metric:logins.count"
].
query_string
.
query
).
to
.
be
(
"@metric:logins.count"
);
expect
(
query
.
aggs
[
"2"
].
aggs
[
"4"
].
date_histogram
.
field
).
to
.
be
(
"@timestamp"
);
});
...
...
@@ -291,7 +291,6 @@ describe('ElasticQueryBuilder', function() {
{
key
:
'key1'
,
operator
:
'='
,
value
:
'value1'
}
]);
expect
(
query
.
query
.
filtered
.
filter
.
bool
.
must
[
1
].
term
[
"key1"
]).
to
.
be
(
"value1"
);
expect
(
query
.
query
.
bool
.
must
[
2
].
term
[
"key1"
]).
to
.
be
(
"value1"
);
});
});
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