-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doc viewer app #2121
Doc viewer app #2121
Changes from 9 commits
7bc5a75
4f0a6e6
de5d29d
703d817
4cda920
446e82c
3b04e44
652ff5c
6aab300
faf0a5b
2bddc7b
18a3d02
a755b73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Takes a hit, merges it with any stored/scripted fields, and with the metaFields | ||
// returns a flattened version | ||
define(function (require) { | ||
var _ = require('lodash'); | ||
return function () { | ||
var self = this; | ||
var scriptFields = {}; | ||
|
||
_.each(self.fields.byType['date'], function (field) { | ||
if (field.indexed) { | ||
scriptFields[field.name] = { | ||
script: 'doc["' + field.name + '"].value' | ||
}; | ||
} | ||
}); | ||
return { | ||
fields: ['*', '_source'], | ||
scriptFields: scriptFields | ||
}; | ||
|
||
}; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
<td colspan="{{ columns.length + 2 }}"> | ||
<a class="pull-right" ng-href="#/doc/{{indexPattern.id}}/{{row._index}}/{{row._type}}/{{row._id}}"> | ||
<small>Link to /{{row._index}}/{{row._type}}/{{row._id}}</small></i> | ||
</a> | ||
<doc-viewer hit="row" filter="filter" index-pattern="indexPattern"></doc-viewer> | ||
</td> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
define(function (require) { | ||
var _ = require('lodash'); | ||
var angular = require('angular'); | ||
|
||
require('components/notify/notify'); | ||
require('components/courier/courier'); | ||
require('components/doc_viewer/doc_viewer'); | ||
require('components/index_patterns/index_patterns'); | ||
|
||
var app = require('modules').get('apps/doc', [ | ||
'kibana/notify', | ||
'kibana/courier', | ||
'kibana/index_patterns' | ||
]); | ||
|
||
require('routes') | ||
.when('/doc/:indexPattern/:index/:type/:id', { | ||
template: require('text!plugins/doc/index.html'), | ||
resolve: { | ||
indexPattern: function (courier, savedSearches, $route) { | ||
return courier.indexPatterns.get($route.current.params.indexPattern); | ||
} | ||
} | ||
}); | ||
|
||
app.controller('doc', function ($scope, $route, es, timefilter) { | ||
|
||
timefilter.enabled = false; | ||
|
||
// Pretty much only need this for formatting, not actually using it for fetching anything. | ||
$scope.indexPattern = $route.current.locals.indexPattern; | ||
|
||
var computedFields = $scope.indexPattern.getComputedFields(); | ||
|
||
es.search({ | ||
index: $route.current.params.index, | ||
type: $route.current.params.type, | ||
body: { | ||
query: { | ||
ids: { | ||
values: [$route.current.params.id] | ||
} | ||
}, | ||
fields: computedFields.fields, | ||
script_fields: computedFields.scriptFields | ||
} | ||
}).then(function (resp) { | ||
if (resp.hits) { | ||
if (resp.hits.total < 1) { | ||
$scope.status = 'notFound'; | ||
} else { | ||
$scope.status = 'found'; | ||
$scope.hit = resp.hits.hits[0]; | ||
} | ||
} | ||
}).catch(function (err) { | ||
$scope.status = 'error'; | ||
$scope.resp = err; | ||
}); | ||
|
||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<div ng-controller="doc" class="app-container"> | ||
|
||
<div class="container-fluid"> | ||
<div class="row"> | ||
|
||
<!-- no results --> | ||
<div class="col-md-12" ng-if="status === 'notFound'"> | ||
<div class="col-md-12"> | ||
<h1>Failed to locate document. <i class="fa fa-meh-o"></i></h1> | ||
|
||
<p> | ||
Unfortunately I could not find any documents matching that id, of that type, in that index. I tried really hard. I wanted it to be there. Sometimes I swear documents grow legs and just walk out of the index. Sneaky. I wish I could offer some advice here, something to make you feel better | ||
</p> | ||
|
||
</div> | ||
</div> | ||
|
||
<!-- no results --> | ||
<div class="col-md-12" ng-if="status === 'error'"> | ||
<div class="col-md-12"> | ||
<h1>This is bad. <i class="fa fa-meh-o"></i></h1> | ||
|
||
<p> | ||
Oh no. Something went very wrong. Its not just that I couldn't find your document, I couldn't even try. The index was missing, or the type. Go check out Elasticsearch, something isn't quite right here. | ||
</p> | ||
|
||
</div> | ||
</div> | ||
|
||
<!-- loading --> | ||
<div class="col-md-12" ng-if="status === undefined"> | ||
<div class="discover-overlay"> | ||
<h2>Searching</h2> | ||
<div class="spinner large"></div> | ||
<div ng-show="fetchStatus">{{fetchStatus.complete}}/{{fetchStatus.total}}</div> | ||
</div> | ||
</div> | ||
|
||
<!-- result --> | ||
<div class="col-md-12" ng-if="status === 'found'"> | ||
<h2><b>Doc:</b> {{hit._index}}/{{hit._type}}/{{hit._id}}</h2> | ||
|
||
<doc-viewer hit="hit" index-pattern="indexPattern"></doc-viewer> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
define(function (require, module, exports) { | ||
require('plugins/doc/controllers/doc'); | ||
require('css!plugins/doc/styles/main.css'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't actually being compiled. Also, there doesn't appear to be any rules in |
||
|
||
var apps = require('registry/apps'); | ||
apps.register(function DocAppModule() { | ||
return { | ||
id: 'doc', | ||
name: 'Doc Viewer', | ||
order: -1 | ||
}; | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@import (reference) "../../../styles/_bootstrap.less"; | ||
@import (reference) "../../../styles/theme/_theme.less"; | ||
@import (reference) "../../../styles/_variables.less"; | ||
|
||
.application-doc { | ||
// Styles here | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No styles apparently. This can be removed. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
define(function (require) { | ||
var angular = require('angular'); | ||
var $ = require('jquery'); | ||
|
||
// Load the kibana app dependencies. | ||
require('angular-route'); | ||
|
||
require('plugins/doc/index'); | ||
|
||
var $scope, createController, $route; | ||
|
||
var init = function (index, type, id) { | ||
|
||
module('kibana'); | ||
|
||
// Stub services | ||
module(function ($provide) { | ||
$provide.service('$route', function (Private) { | ||
this.current = { | ||
locals: { | ||
indexPattern: Private(require('fixtures/stubbed_logstash_index_pattern')) | ||
}, | ||
params: { | ||
index: index || 'myIndex', | ||
type: type || 'myType', | ||
id: id || 'myId' | ||
} | ||
}; | ||
}); | ||
}); | ||
|
||
// Create the scope | ||
inject(function ($rootScope, $controller, _$route_) { | ||
|
||
$route = _$route_; | ||
$scope = $rootScope.$new(); | ||
|
||
createController = function () { | ||
return $controller('doc', { | ||
'$scope': $scope | ||
}); | ||
}; | ||
}); | ||
}; | ||
|
||
|
||
describe('Doc app controller', function () { | ||
|
||
beforeEach(function () { | ||
init(); | ||
}); | ||
|
||
it('should have $scope.foo', function () { | ||
createController(); | ||
}); | ||
|
||
}); | ||
|
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
define(function (require) { | ||
return ['get computed fields', function () { | ||
var _ = require('lodash'); | ||
|
||
var indexPattern, getComputedFields, fn; | ||
beforeEach(module('kibana')); | ||
beforeEach(inject(function (Private, $injector) { | ||
indexPattern = Private(require('fixtures/stubbed_logstash_index_pattern')); | ||
getComputedFields = require('components/index_patterns/_get_computed_fields'); | ||
indexPattern.getComputedFields = getComputedFields.bind(indexPattern); | ||
fn = indexPattern.getComputedFields; | ||
|
||
})); | ||
|
||
it('should be a function', function () { | ||
expect(fn).to.be.a(Function); | ||
}); | ||
|
||
it('should request all stored fields', function () { | ||
expect(fn().fields).to.contain('*'); | ||
}); | ||
|
||
it('should request _source seperately', function () { | ||
expect(fn().fields).to.contain('_source'); | ||
}); | ||
|
||
it('should request date fields as scripts', function () { | ||
expect(fn().scriptFields).to.include.keys('@timestamp'); | ||
expect(fn().scriptFields).to.not.include.keys('bytes'); | ||
}); | ||
|
||
|
||
}]; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Why a search here?
A: Elasticsearch GET API doesn't support stored or scripted fields, have to go through the search API
Q: Well then why didn't you use a searchSource?
A: It seemed wasteful to start up a temporary indexPattern and searchSource for one request. I would need to new up an indexPattern as the existing one could match some range of indices, and I need exactly one index. The indexPattern that does get loaded here is only used for formatters and scripted fields retrieval.