mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
removed dependence on elasticsearch js client from search, will try to remove this depdence in other places and just use $http, elasticsearch js client is to big and does not provide enough value
This commit is contained in:
parent
0a3d4a5ab0
commit
95925aafb1
@ -9,7 +9,7 @@ function (angular, _, config, $) {
|
||||
|
||||
var module = angular.module('kibana.controllers');
|
||||
|
||||
module.controller('SearchCtrl', function($scope, $rootScope, $element, $location, ejsResource) {
|
||||
module.controller('SearchCtrl', function($scope, $rootScope, $element, $location, ejsResource, elasticClient) {
|
||||
|
||||
$scope.init = function() {
|
||||
$scope.ejs = ejsResource(config.elasticsearch, config.elasticsearchBasicAuth);
|
||||
@ -49,30 +49,31 @@ function (angular, _, config, $) {
|
||||
}
|
||||
};
|
||||
|
||||
$scope.searchDasboards = function(query) {
|
||||
var request = $scope.ejs.Request().indices(config.grafana_index).types('dashboard');
|
||||
var tagsOnly = query.indexOf('tags!:') === 0;
|
||||
$scope.searchDasboards = function(queryString) {
|
||||
var tagsOnly = queryString.indexOf('tags!:') === 0;
|
||||
if (tagsOnly) {
|
||||
var tagsQuery = query.substring(6, query.length);
|
||||
query = 'tags:' + tagsQuery + '*';
|
||||
var tagsQuery = queryString.substring(6, queryString.length);
|
||||
queryString = 'tags:' + tagsQuery + '*';
|
||||
}
|
||||
else {
|
||||
if (query.length === 0) {
|
||||
query = 'title:';
|
||||
if (queryString.length === 0) {
|
||||
queryString = 'title:';
|
||||
}
|
||||
|
||||
if (query[query.length - 1] !== '*') {
|
||||
query += '*';
|
||||
if (queryString[queryString.length - 1] !== '*') {
|
||||
queryString += '*';
|
||||
}
|
||||
}
|
||||
|
||||
return request
|
||||
.query($scope.ejs.QueryStringQuery(query))
|
||||
.sort('_uid')
|
||||
.facet($scope.ejs.TermsFacet("tags").field("tags").order('term').size(50))
|
||||
.size(20).doSearch()
|
||||
.then(function(results) {
|
||||
var query = {
|
||||
query: { query_string: { query: queryString } },
|
||||
facets: { tags: { terms: { field: "tags", order: "term", size: 50 } } },
|
||||
size: 20,
|
||||
sort: ["_uid"]
|
||||
};
|
||||
|
||||
return elasticClient.post('dashboard/_search', query)
|
||||
.then(function(results) {
|
||||
if(_.isUndefined(results.hits)) {
|
||||
$scope.results.dashboards = [];
|
||||
$scope.results.tags = [];
|
||||
@ -115,32 +116,6 @@ function (angular, _, config, $) {
|
||||
$scope.searchDasboards(queryStr);
|
||||
return;
|
||||
}
|
||||
|
||||
queryStr = queryStr.substring(2, queryStr.length);
|
||||
|
||||
var words = queryStr.split(' ');
|
||||
var query = $scope.ejs.BoolQuery();
|
||||
var terms = _.map(words, function(word) {
|
||||
return $scope.ejs.MatchQuery('metricPath_ng', word).boost(1.2);
|
||||
});
|
||||
|
||||
var ngramQuery = $scope.ejs.BoolQuery();
|
||||
ngramQuery.must(terms);
|
||||
|
||||
var fieldMatchQuery = $scope.ejs.FieldQuery('metricPath', queryStr + "*").boost(1.2);
|
||||
query.should([ngramQuery, fieldMatchQuery]);
|
||||
|
||||
var request = $scope.ejs.Request().indices(config.grafana_index).types('metricKey');
|
||||
var results = request.query(query).size(20).doSearch();
|
||||
|
||||
results.then(function(results) {
|
||||
if (results && results.hits && results.hits.hits.length > 0) {
|
||||
$scope.results.metrics = { metrics: results.hits.hits };
|
||||
}
|
||||
else {
|
||||
$scope.results.metrics = { metric: [] };
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.openSearch = function (evt) {
|
||||
|
@ -9,6 +9,6 @@ define([
|
||||
'./annotationsSrv',
|
||||
'./playlistSrv',
|
||||
'./unsavedChangesSrv',
|
||||
'./elasticsearch/es-client2',
|
||||
'./elasticsearch/es-client',
|
||||
],
|
||||
function () {});
|
35
src/app/services/elasticsearch/es-client.js
Normal file
35
src/app/services/elasticsearch/es-client.js
Normal file
@ -0,0 +1,35 @@
|
||||
define([
|
||||
'angular',
|
||||
'config'
|
||||
],
|
||||
function(angular, config) {
|
||||
"use strict";
|
||||
|
||||
var module = angular.module('kibana.services');
|
||||
|
||||
module.service('elasticClient', function($http) {
|
||||
|
||||
this.post = function(url, data) {
|
||||
|
||||
var options = {
|
||||
url: config.elasticsearch + "/" + config.grafana_index + "/" + url,
|
||||
method: 'POST',
|
||||
data: data
|
||||
};
|
||||
|
||||
if (config.elasticsearchBasicAuth) {
|
||||
options.headers = {
|
||||
"Authorization": "Basic " + config.elasticsearchBasicAuth
|
||||
};
|
||||
}
|
||||
|
||||
return $http(options)
|
||||
.then(function(results) {
|
||||
return results.data;
|
||||
}, function(results) {
|
||||
return results.data;
|
||||
});
|
||||
};
|
||||
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user