Commit 95925aaf by Torkel Ödegaard

removed dependence on elasticsearch js client from search, will try to remove…

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
parent 0a3d4a5a
...@@ -9,7 +9,7 @@ function (angular, _, config, $) { ...@@ -9,7 +9,7 @@ function (angular, _, config, $) {
var module = angular.module('kibana.controllers'); 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.init = function() {
$scope.ejs = ejsResource(config.elasticsearch, config.elasticsearchBasicAuth); $scope.ejs = ejsResource(config.elasticsearch, config.elasticsearchBasicAuth);
...@@ -49,30 +49,31 @@ function (angular, _, config, $) { ...@@ -49,30 +49,31 @@ function (angular, _, config, $) {
} }
}; };
$scope.searchDasboards = function(query) { $scope.searchDasboards = function(queryString) {
var request = $scope.ejs.Request().indices(config.grafana_index).types('dashboard'); var tagsOnly = queryString.indexOf('tags!:') === 0;
var tagsOnly = query.indexOf('tags!:') === 0;
if (tagsOnly) { if (tagsOnly) {
var tagsQuery = query.substring(6, query.length); var tagsQuery = queryString.substring(6, queryString.length);
query = 'tags:' + tagsQuery + '*'; queryString = 'tags:' + tagsQuery + '*';
} }
else { else {
if (query.length === 0) { if (queryString.length === 0) {
query = 'title:'; queryString = 'title:';
} }
if (query[query.length - 1] !== '*') { if (queryString[queryString.length - 1] !== '*') {
query += '*'; queryString += '*';
} }
} }
return request var query = {
.query($scope.ejs.QueryStringQuery(query)) query: { query_string: { query: queryString } },
.sort('_uid') facets: { tags: { terms: { field: "tags", order: "term", size: 50 } } },
.facet($scope.ejs.TermsFacet("tags").field("tags").order('term').size(50)) size: 20,
.size(20).doSearch() sort: ["_uid"]
.then(function(results) { };
return elasticClient.post('dashboard/_search', query)
.then(function(results) {
if(_.isUndefined(results.hits)) { if(_.isUndefined(results.hits)) {
$scope.results.dashboards = []; $scope.results.dashboards = [];
$scope.results.tags = []; $scope.results.tags = [];
...@@ -115,32 +116,6 @@ function (angular, _, config, $) { ...@@ -115,32 +116,6 @@ function (angular, _, config, $) {
$scope.searchDasboards(queryStr); $scope.searchDasboards(queryStr);
return; 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) { $scope.openSearch = function (evt) {
......
...@@ -9,6 +9,6 @@ define([ ...@@ -9,6 +9,6 @@ define([
'./annotationsSrv', './annotationsSrv',
'./playlistSrv', './playlistSrv',
'./unsavedChangesSrv', './unsavedChangesSrv',
'./elasticsearch/es-client2', './elasticsearch/es-client',
], ],
function () {}); function () {});
\ No newline at end of file
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;
});
};
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment