mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Encapsulated ES calls into an es module. Introduced api_1_0 (currently a copy of api_0_90) . Version is auto detected and set based on GET / .
This commit is contained in:
parent
b1b4c84857
commit
3ccd1dbe70
23 changed files with 1798 additions and 92 deletions
|
@ -7,10 +7,11 @@ define([
|
|||
'mappings',
|
||||
'output',
|
||||
'misc_inputs',
|
||||
'es',
|
||||
'utils',
|
||||
'_'
|
||||
],
|
||||
function (curl, $helpPopup, history, input, $, mappings, output, miscInputs, utils, _) {
|
||||
function (curl, $helpPopup, history, input, $, mappings, output, miscInputs, es, utils, _) {
|
||||
'use strict';
|
||||
|
||||
$(document.body).removeClass('fouc');
|
||||
|
@ -26,20 +27,19 @@ define([
|
|||
|
||||
$("#notification").text("Calling ES....").css("visibility", "visible");
|
||||
|
||||
var es_server = $esServer.val();
|
||||
var es_url = req.url;
|
||||
var es_path = req.url;
|
||||
var es_method = req.method;
|
||||
var es_data = req.data.join("\n");
|
||||
if (es_data) es_data += "\n"; //append a new line for bulk requests.
|
||||
|
||||
utils.callES(es_server, es_url, es_method, es_data, null, function (xhr, status) {
|
||||
es.send(es_method, es_path, es_data, null, function (xhr, status) {
|
||||
$("#notification").text("").css("visibility", "hidden");
|
||||
if (typeof xhr.status == "number" &&
|
||||
((xhr.status >= 400 && xhr.status < 600) ||
|
||||
(xhr.status >= 200 && xhr.status < 300)
|
||||
)) {
|
||||
// we have someone on the other side. Add to history
|
||||
history.addToHistory(es_server, es_url, es_method, es_data);
|
||||
history.addToHistory(es.getBaseUrl(), es_path, es_method, es_data);
|
||||
|
||||
|
||||
var value = xhr.responseText;
|
||||
|
@ -64,8 +64,7 @@ define([
|
|||
// set the value of the server and/or the input and clear the output
|
||||
function resetToValues(server, content) {
|
||||
if (server != null) {
|
||||
$esServer.val(server);
|
||||
mappings.notifyServerChange(server);
|
||||
es.setBaseUrl(server);
|
||||
}
|
||||
if (content != null) {
|
||||
input.update(content);
|
||||
|
@ -255,4 +254,6 @@ define([
|
|||
});
|
||||
}
|
||||
|
||||
mappings.onInitComplete();
|
||||
|
||||
});
|
||||
|
|
96
sense/app/es.js
Normal file
96
sense/app/es.js
Normal file
|
@ -0,0 +1,96 @@
|
|||
define([
|
||||
"_", "jquery", "exports"
|
||||
], function (_, $, exports) {
|
||||
"use strict";
|
||||
|
||||
var baseUrl;
|
||||
var serverChangeListeners = [];
|
||||
var esVersion = [];
|
||||
|
||||
exports.getBaseUrl = function () {
|
||||
return baseUrl;
|
||||
};
|
||||
exports.getVersion = function () {
|
||||
return esVersion;
|
||||
};
|
||||
|
||||
exports.send = function (method, path, data, successCallback, completeCallback, server) {
|
||||
server = server || exports.getBaseUrl();
|
||||
path = exports.constructESUrl(server, path);
|
||||
var uname_password_re = /^(https?:\/\/)?(?:(?:([^\/]*):)?([^\/]*?)@)?(.*)$/;
|
||||
var url_parts = path.match(uname_password_re);
|
||||
|
||||
var uname = url_parts[2];
|
||||
var password = url_parts[3];
|
||||
path = url_parts[1] + url_parts[4];
|
||||
console.log("Calling " + path + " (uname: " + uname + " pwd: " + password + ")");
|
||||
if (data && method == "GET") {
|
||||
method = "POST";
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: path,
|
||||
data: method == "GET" ? null : data,
|
||||
password: password,
|
||||
cache: false,
|
||||
username: uname,
|
||||
crossDomain: true,
|
||||
type: method,
|
||||
dataType: "json",
|
||||
complete: completeCallback,
|
||||
success: successCallback
|
||||
});
|
||||
};
|
||||
|
||||
exports.constructESUrl = function (server, path) {
|
||||
if (!path) {
|
||||
path = server;
|
||||
server = exports.getBaseUrl();
|
||||
}
|
||||
if (path.indexOf("://") >= 0) {
|
||||
return path;
|
||||
}
|
||||
if (server.indexOf("://") < 0) {
|
||||
server = "http://" + server;
|
||||
}
|
||||
if (server.substr(-1) == "/") {
|
||||
server = server.substr(0, server.length - 1);
|
||||
}
|
||||
if (path.charAt(0) === "/") {
|
||||
path = path.substr(1);
|
||||
}
|
||||
|
||||
return server + "/" + path;
|
||||
};
|
||||
|
||||
|
||||
exports.setBaseUrl = function (base) {
|
||||
if (baseUrl !== base) {
|
||||
var old = baseUrl;
|
||||
baseUrl = base;
|
||||
exports.send("GET", "/", null, null, function (xhr, status) {
|
||||
if (xhr.status === 200) {
|
||||
// parse for version
|
||||
var value = xhr.responseText;
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
if (value.version && value.version.number) {
|
||||
esVersion = value.version.number.split(".");
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
}
|
||||
}
|
||||
_.each(serverChangeListeners, function (cb) {
|
||||
cb(base, old)
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
exports.addServerChangeListener = function (cb) {
|
||||
serverChangeListeners.push(cb);
|
||||
}
|
||||
}
|
||||
);
|
|
@ -2,11 +2,13 @@ define([
|
|||
'_',
|
||||
'exports',
|
||||
'mappings',
|
||||
'kb/api_0_90'
|
||||
], function (_, exports, mappings, api_0_90) {
|
||||
'es',
|
||||
'kb/api_0_90',
|
||||
'kb/api_1_0'
|
||||
], function (_, exports, mappings, es, api_0_90, api_1_0) {
|
||||
'use strict';
|
||||
|
||||
var ACTIVE_API = api_0_90.api;
|
||||
var ACTIVE_API = api_0_90;
|
||||
|
||||
|
||||
function expandAliases(indices) {
|
||||
|
@ -38,8 +40,22 @@ define([
|
|||
|
||||
function setActiveApi(api) {
|
||||
ACTIVE_API = api;
|
||||
console.log("setting api to " + api.name);
|
||||
}
|
||||
|
||||
es.addServerChangeListener(function () {
|
||||
var version = es.getVersion();
|
||||
if (!version || version.length == 0) {
|
||||
setActiveApi(api_0_90);
|
||||
}
|
||||
else if (version[0] === "1") {
|
||||
setActiveApi(api_1_0);
|
||||
}
|
||||
else {
|
||||
setActiveApi(api_0_90);
|
||||
}
|
||||
});
|
||||
|
||||
exports.setActiveApi = setActiveApi;
|
||||
exports.getGlobalAutocompleteRules = getGlobalAutocompleteRules;
|
||||
exports.getEndpointAutocomplete = getEndpointAutocomplete;
|
||||
|
|
|
@ -2,9 +2,10 @@ define([ '_', 'exports'],
|
|||
function (_, exports) {
|
||||
'use strict';
|
||||
|
||||
function Api() {
|
||||
function Api(name) {
|
||||
this.global_rules = {};
|
||||
this.endpoints = {};
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
function escapeRegex(text) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
define([
|
||||
'_',
|
||||
'exports',
|
||||
'./api',
|
||||
'./api_0_90/aliases',
|
||||
'./api_0_90/cluster',
|
||||
|
@ -15,15 +14,14 @@ define([
|
|||
'./api_0_90/settings',
|
||||
'./api_0_90/templates',
|
||||
'./api_0_90/warmers'
|
||||
], function (_, exports, api) {
|
||||
], function (_, api) {
|
||||
'use strict';
|
||||
|
||||
var api_0_90 = new api.Api();
|
||||
var api_0_90 = new api.Api("api_0_90");
|
||||
|
||||
_(arguments).rest(3).each(function (apiSection) {
|
||||
apiSection(api_0_90);
|
||||
});
|
||||
|
||||
exports.api = api_0_90;
|
||||
return exports;
|
||||
return api_0_90;
|
||||
});
|
28
sense/app/kb/api_1_0.js
Normal file
28
sense/app/kb/api_1_0.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
define([
|
||||
'_',
|
||||
'./api',
|
||||
'./api_1_0/aliases',
|
||||
'./api_1_0/cluster',
|
||||
'./api_1_0/facets',
|
||||
'./api_1_0/filter',
|
||||
'./api_1_0/globals',
|
||||
'./api_1_0/indices',
|
||||
'./api_1_0/mappings',
|
||||
'./api_1_0/misc',
|
||||
'./api_1_0/query',
|
||||
'./api_1_0/search',
|
||||
'./api_1_0/settings',
|
||||
'./api_1_0/templates',
|
||||
'./api_1_0/warmers'
|
||||
], function (_, api) {
|
||||
'use strict';
|
||||
|
||||
var api_1_0 = new api.Api("api_1_0");
|
||||
|
||||
|
||||
_(arguments).rest(3).each(function (apiSection) {
|
||||
apiSection(api_1_0);
|
||||
});
|
||||
|
||||
return api_1_0;
|
||||
});
|
40
sense/app/kb/api_1_0/aliases.js
Normal file
40
sense/app/kb/api_1_0/aliases.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(api) {
|
||||
api.addEndpointDescription('_aliases', {
|
||||
match: /_aliases/,
|
||||
def_method: 'GET',
|
||||
methods: ['GET', 'POST'],
|
||||
endpoint_autocomplete: [
|
||||
'_aliases'
|
||||
],
|
||||
indices_mode: 'multi',
|
||||
types_mode: 'none',
|
||||
doc_id_mode: 'none',
|
||||
data_autocomplete_rules: {
|
||||
'actions': {
|
||||
__template: [
|
||||
{ 'add': { 'index': 'test1', 'alias': 'alias1' } }
|
||||
],
|
||||
__any_of: [
|
||||
{
|
||||
add: {
|
||||
index: '$INDEX$',
|
||||
alias: '',
|
||||
filter: {},
|
||||
routing: '1',
|
||||
search_routing: '1,2',
|
||||
index_routing: '1'
|
||||
},
|
||||
remove: {
|
||||
index: '',
|
||||
alias: ''
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
40
sense/app/kb/api_1_0/cluster.js
Normal file
40
sense/app/kb/api_1_0/cluster.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(api) {
|
||||
api.addEndpointDescription('_cluster/nodes/stats', {
|
||||
methods: ['GET'],
|
||||
indices_mode: 'none',
|
||||
types_mode: 'none'
|
||||
});
|
||||
|
||||
api.addEndpointDescription('_cluster/state', {
|
||||
methods: ['GET'],
|
||||
endpoint_autocomplete: ['_cluster/state'],
|
||||
indices_mode: 'none',
|
||||
types_mode: 'none'
|
||||
});
|
||||
|
||||
api.addEndpointDescription('_cluster/health', {
|
||||
methods: ['GET'],
|
||||
endpoint_autocomplete: ['_cluster/health'],
|
||||
indices_mode: 'none',
|
||||
types_mode: 'none'
|
||||
});
|
||||
|
||||
api.addEndpointDescription('_cluster/settings', {
|
||||
methods: ['GET', 'PUT'],
|
||||
endpoint_autocomplete: ['_cluster/settings'],
|
||||
indices_mode: 'none',
|
||||
types_mode: 'none',
|
||||
data_autocomplete_rules: {
|
||||
persistent: {
|
||||
'routing.allocation.same_shard.host': { __one_of: [ false, true ]}
|
||||
},
|
||||
transient: {
|
||||
__scope_link: '.persistent'
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
118
sense/app/kb/api_1_0/facets.js
Normal file
118
sense/app/kb/api_1_0/facets.js
Normal file
|
@ -0,0 +1,118 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(api) {
|
||||
api.addGlobalAutocompleteRules('facets', {
|
||||
'*': {
|
||||
terms: {
|
||||
__template: {
|
||||
field: 'FIELD',
|
||||
size: 10
|
||||
},
|
||||
field: '$FIELD$',
|
||||
fields: ['$FIELD$'],
|
||||
size: 10,
|
||||
script: '',
|
||||
script_field: '',
|
||||
order: {
|
||||
__one_of: ['count', 'term', 'reverse_count', 'reverse_term']
|
||||
},
|
||||
all_terms: {
|
||||
__one_of: [false, true]
|
||||
},
|
||||
exclude: ['TERM'],
|
||||
regex: '',
|
||||
regex_flags: ''
|
||||
},
|
||||
range: {
|
||||
__template: {
|
||||
field: 'FIELD',
|
||||
ranges: [
|
||||
{
|
||||
'to': 50
|
||||
},
|
||||
{
|
||||
'from': 20,
|
||||
'to': 70
|
||||
},
|
||||
{
|
||||
'from': 70,
|
||||
'to': 120
|
||||
},
|
||||
{
|
||||
'from': 150
|
||||
}
|
||||
]
|
||||
},
|
||||
field: '$FIELD$',
|
||||
ranges: [
|
||||
{
|
||||
to: 10,
|
||||
from: 20
|
||||
}
|
||||
]
|
||||
},
|
||||
histogram: {
|
||||
__template: {
|
||||
field: 'FIELD',
|
||||
interval: 100
|
||||
},
|
||||
field: '$FIELD$',
|
||||
interval: 100,
|
||||
time_interval: '1.5h',
|
||||
key_field: '$FIELD$',
|
||||
value_field: '$FIELD$',
|
||||
key_script: '',
|
||||
value_script: '',
|
||||
params: {}
|
||||
},
|
||||
date_histogram: {
|
||||
__template: {
|
||||
field: 'FIELD',
|
||||
'interval': 'day'
|
||||
},
|
||||
field: '$FIELD$',
|
||||
interval: {
|
||||
__one_of: ['year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', '1h', '1d', '1w']
|
||||
},
|
||||
post_zone: -1,
|
||||
pre_zone: -1,
|
||||
factor: 1000,
|
||||
pre_offset: '1d',
|
||||
post_offset: '1d',
|
||||
key_field: '$FIELD$',
|
||||
value_field: '$FIELD$',
|
||||
value_script: ''
|
||||
},
|
||||
filter: {},
|
||||
query: {},
|
||||
facet_filter: {
|
||||
__scope_link: 'GLOBAL.filter'
|
||||
},
|
||||
statistical: {
|
||||
__template: {
|
||||
field: 'FIELD'
|
||||
},
|
||||
field: '$FIELD$',
|
||||
fields: ['$FIELD$'],
|
||||
script: ''
|
||||
},
|
||||
terms_stats: {
|
||||
__template: {
|
||||
key_field: 'FIELD',
|
||||
value_field: 'FIELD'
|
||||
},
|
||||
key_field: '$FIELD$',
|
||||
value_field: '$FIELD$',
|
||||
value_script: '',
|
||||
size: 10,
|
||||
order: {
|
||||
__one_of: ['count', 'term', 'reverse_term', 'reverse_count', 'total', 'reverse_total',
|
||||
'min', 'reverse_min', 'max', 'reverse_max', 'mean', 'reverse_mean'
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
429
sense/app/kb/api_1_0/filter.js
Normal file
429
sense/app/kb/api_1_0/filter.js
Normal file
|
@ -0,0 +1,429 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
var filters = {};
|
||||
|
||||
filters.and = {
|
||||
__template: {
|
||||
filters: [
|
||||
{}
|
||||
]
|
||||
},
|
||||
filters: [
|
||||
{
|
||||
__scope_link: '.filter'
|
||||
}
|
||||
],
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.bool = {
|
||||
must: [
|
||||
{
|
||||
__scope_link: '.filter'
|
||||
}
|
||||
],
|
||||
must_not: [
|
||||
{
|
||||
__scope_link: '.filter'
|
||||
}
|
||||
],
|
||||
should: [
|
||||
{
|
||||
__scope_link: '.filter'
|
||||
}
|
||||
],
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.exists = {
|
||||
__template: {
|
||||
'FIELD': 'VALUE'
|
||||
},
|
||||
'$FIELD$': ''
|
||||
};
|
||||
|
||||
|
||||
filters.ids = {
|
||||
__template: {
|
||||
'values': ['ID']
|
||||
},
|
||||
'type': '$TYPE$',
|
||||
'values': ['']
|
||||
};
|
||||
|
||||
|
||||
filters.limit = {
|
||||
__template: {
|
||||
value: 100
|
||||
},
|
||||
value: 100
|
||||
};
|
||||
|
||||
|
||||
filters.type = {
|
||||
__template: {
|
||||
value: 'TYPE'
|
||||
},
|
||||
value: '$TYPE$'
|
||||
};
|
||||
|
||||
|
||||
filters.geo_bounding_box = {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
'top_left': {
|
||||
'lat': 40.73,
|
||||
'lon': -74.1
|
||||
},
|
||||
'bottom_right': {
|
||||
'lat': 40.717,
|
||||
'lon': -73.99
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
'$FIELD$': {
|
||||
top_left: {
|
||||
lat: 40.73,
|
||||
lon: -74.1
|
||||
},
|
||||
bottom_right: {
|
||||
lat: 40.73,
|
||||
lon: -74.1
|
||||
}
|
||||
},
|
||||
type: {
|
||||
__one_of: ['memory', 'indexed']
|
||||
},
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.geo_distance = {
|
||||
__template: {
|
||||
distance: 100,
|
||||
distance_unit: 'km',
|
||||
'FIELD': {
|
||||
lat: 40.73,
|
||||
lon: -74.1
|
||||
}
|
||||
},
|
||||
distance: 100,
|
||||
distance_unit: {
|
||||
__one_of: ['km', 'miles']
|
||||
},
|
||||
distance_type: {
|
||||
__one_of: ['arc', 'plane']
|
||||
},
|
||||
optimize_bbox: {
|
||||
__one_of: ['memory', 'indexed', 'none']
|
||||
},
|
||||
'$FIELD$': {
|
||||
lat: 40.73,
|
||||
lon: -74.1
|
||||
},
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.geo_distance_range = {
|
||||
__template: {
|
||||
from: 100,
|
||||
to: 200,
|
||||
distance_unit: 'km',
|
||||
'FIELD': {
|
||||
lat: 40.73,
|
||||
lon: -74.1
|
||||
}
|
||||
},
|
||||
from: 100,
|
||||
to: 200,
|
||||
|
||||
distance_unit: {
|
||||
__one_of: ['km', 'miles']
|
||||
},
|
||||
distance_type: {
|
||||
__one_of: ['arc', 'plane']
|
||||
},
|
||||
include_lower: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
include_upper: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
|
||||
'$FIELD$': {
|
||||
lat: 40.73,
|
||||
lon: -74.1
|
||||
},
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.geo_polygon = {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
'points': [
|
||||
{
|
||||
lat: 40.73,
|
||||
lon: -74.1
|
||||
},
|
||||
{
|
||||
lat: 40.83,
|
||||
lon: -75.1
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
'$FIELD$': {
|
||||
points: [
|
||||
{
|
||||
lat: 40.73,
|
||||
lon: -74.1
|
||||
}
|
||||
]
|
||||
},
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.geo_shape = {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
shape: {
|
||||
type: 'envelope',
|
||||
coordinates: [
|
||||
[-45, 45],
|
||||
[45, -45]
|
||||
]
|
||||
},
|
||||
'relation': 'within'
|
||||
}
|
||||
},
|
||||
'$FIELD$': {
|
||||
shape: {
|
||||
type: '',
|
||||
coordinates: []
|
||||
},
|
||||
indexed_shape: {
|
||||
id: '',
|
||||
index: '$INDEX$',
|
||||
type: '$TYPE$',
|
||||
shape_field_name: 'shape'
|
||||
},
|
||||
relation: {
|
||||
__one_of: ['within', 'intersects', 'disjoint']
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.has_child = {
|
||||
__template: {
|
||||
type: 'TYPE',
|
||||
query: {}
|
||||
},
|
||||
type: '$TYPE$',
|
||||
query: {},
|
||||
_scope: ''
|
||||
};
|
||||
|
||||
|
||||
filters.has_parent = {
|
||||
__template: {
|
||||
type: 'TYPE',
|
||||
query: {}
|
||||
},
|
||||
type: '$TYPE$',
|
||||
query: {},
|
||||
_scope: ''
|
||||
};
|
||||
|
||||
|
||||
filters.m = filters.missing = {
|
||||
__template: {
|
||||
field: 'FIELD'
|
||||
},
|
||||
existence: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
null_value: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
field: '$FIELD$'
|
||||
};
|
||||
|
||||
|
||||
filters.not = {
|
||||
__template: {
|
||||
filter: {}
|
||||
},
|
||||
filter: {
|
||||
__scope_link: '.filter'
|
||||
},
|
||||
_cache: {
|
||||
__one_of: [true, false]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.numeric_range = {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
from: 10,
|
||||
to: 20
|
||||
}
|
||||
},
|
||||
"$FIELD$": {
|
||||
from: 1,
|
||||
to: 20,
|
||||
include_lower: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
include_upper: {
|
||||
__one_of: [true, false]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.or = {
|
||||
__template: {
|
||||
filters: [
|
||||
{}
|
||||
]
|
||||
},
|
||||
filters: [
|
||||
{
|
||||
__scope_link: '.filter'
|
||||
}
|
||||
],
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.prefix = {
|
||||
__template: {
|
||||
'FIELD': 'VALUE'
|
||||
},
|
||||
'$FIELD$': '',
|
||||
_cache: {
|
||||
__one_of: [true, false]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.query = {
|
||||
__scope_link: '.query'
|
||||
};
|
||||
|
||||
|
||||
filters.fquery = {
|
||||
__template: {
|
||||
query: {},
|
||||
_cache: true
|
||||
},
|
||||
query: {
|
||||
__scope_link: '.query'
|
||||
},
|
||||
_cache: {
|
||||
__one_of: [true, false]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.range = {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
from: 10,
|
||||
to: 20
|
||||
}
|
||||
},
|
||||
"$FIELD$": {
|
||||
from: 1,
|
||||
to: 20,
|
||||
include_lower: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
include_upper: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.script = {
|
||||
__template: {
|
||||
script: 'SCRIPT',
|
||||
params: {}
|
||||
},
|
||||
script: '',
|
||||
params: {},
|
||||
_cache: {
|
||||
__one_of: [true, false]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.term = {
|
||||
__template: {
|
||||
'FIELD': 'VALUE'
|
||||
},
|
||||
'$FIELD$': '',
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.terms = {
|
||||
__template: {
|
||||
'FIELD': ['VALUE1', 'VALUE2']
|
||||
},
|
||||
field: ['$FIELD$'],
|
||||
execution: {
|
||||
__one_of: ['plain', 'bool', 'and', 'or', 'bool_nocache', 'and_nocache', 'or_nocache']
|
||||
},
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.nested = {
|
||||
__template: {
|
||||
path: 'path_to_nested_doc',
|
||||
query: {}
|
||||
},
|
||||
query: {},
|
||||
path: '',
|
||||
_cache: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
_name: ''
|
||||
};
|
||||
|
||||
return function init(api) {
|
||||
api.addGlobalAutocompleteRules('filter', filters);
|
||||
};
|
||||
});
|
26
sense/app/kb/api_1_0/globals.js
Normal file
26
sense/app/kb/api_1_0/globals.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(api) {
|
||||
api.addGlobalAutocompleteRules('highlight', {
|
||||
pre_tags: {},
|
||||
post_tags: {},
|
||||
tags_schema: {},
|
||||
fields: {
|
||||
'$FIELD$': {
|
||||
fragment_size: 20,
|
||||
number_of_fragments: 3
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// only used with scope links as there is no common name for scripts
|
||||
api.addGlobalAutocompleteRules('SCRIPT_ENV', {
|
||||
__template: { 'script': ''},
|
||||
script: '',
|
||||
lang: '',
|
||||
params: {}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
51
sense/app/kb/api_1_0/indices.js
Normal file
51
sense/app/kb/api_1_0/indices.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(api) {
|
||||
api.addEndpointDescription('_refresh', {
|
||||
def_method: 'POST',
|
||||
methods: ['POST'],
|
||||
endpoint_autocomplete: [
|
||||
'_refresh'
|
||||
],
|
||||
indices_mode: 'multi'
|
||||
});
|
||||
|
||||
api.addEndpointDescription('_stats', {
|
||||
def_method: 'GET',
|
||||
methods: ['GET'],
|
||||
endpoint_autocomplete: [
|
||||
'_stats'
|
||||
],
|
||||
indices_mode: 'multi'
|
||||
});
|
||||
|
||||
api.addEndpointDescription('_segments', {
|
||||
def_method: 'GET',
|
||||
methods: ['GET'],
|
||||
endpoint_autocomplete: [
|
||||
'_segments'
|
||||
],
|
||||
indices_mode: 'multi'
|
||||
});
|
||||
|
||||
api.addEndpointDescription('__create_index__', {
|
||||
methods: ['PUT', 'DELETE'],
|
||||
indices_mode: 'single',
|
||||
types_mode: 'none',
|
||||
match: '^/?$',
|
||||
endpoint_autocomplete: [
|
||||
''
|
||||
],
|
||||
data_autocomplete_rules: {
|
||||
mappings: {
|
||||
__scope_link: '_mapping'
|
||||
},
|
||||
settings: {
|
||||
__scope_link: '_settings.index'
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
128
sense/app/kb/api_1_0/mappings.js
Normal file
128
sense/app/kb/api_1_0/mappings.js
Normal file
|
@ -0,0 +1,128 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(api) {
|
||||
api.addEndpointDescription('_mapping', {
|
||||
def_method: 'GET',
|
||||
methods: ['GET', 'PUT'],
|
||||
indices_mode: 'multi',
|
||||
types_mode: 'multi',
|
||||
data_autocomplete_rules: {
|
||||
'$TYPE$': {
|
||||
__template: {
|
||||
properties: {
|
||||
'FIELD': {}
|
||||
}
|
||||
},
|
||||
'_parent': {
|
||||
__template: {
|
||||
'type': ''
|
||||
},
|
||||
'type': '$TYPE$'
|
||||
},
|
||||
'index_analyzer': 'standard',
|
||||
'search_analyzer': 'standard',
|
||||
'analyzer': 'standard',
|
||||
'dynamic_date_formats': ['yyyy-MM-dd'],
|
||||
'date_detection': {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
'numeric_detection': {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
'properties': {
|
||||
'*': {
|
||||
type: {
|
||||
__one_of: ['string', 'float', 'double', 'byte', 'short', 'integer', 'long', 'date', 'boolean',
|
||||
'binary', 'object', 'nested', 'multi_field'
|
||||
]
|
||||
},
|
||||
|
||||
// strings
|
||||
index_name: '',
|
||||
store: {
|
||||
__one_of: ['no', 'yes']
|
||||
},
|
||||
index: {
|
||||
__one_of: ['analyzed', 'not_analyzed', 'no']
|
||||
},
|
||||
term_vector: {
|
||||
__one_of: ['no', 'yes', 'with_offsets', 'with_positions', 'with_positions_offsets']
|
||||
},
|
||||
boost: 1.0,
|
||||
null_value: '',
|
||||
omit_norms: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
index_options: {
|
||||
__one_of: ['docs', 'freqs', 'positions']
|
||||
},
|
||||
analyzer: 'standard',
|
||||
index_analyzer: 'standard',
|
||||
search_analyzer: 'standard',
|
||||
include_in_all: {
|
||||
__one_of: [false, true]
|
||||
},
|
||||
ignore_above: 10,
|
||||
position_offset_gap: 0,
|
||||
|
||||
// numeric
|
||||
precision_step: 4,
|
||||
ignore_malformed: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
|
||||
// dates
|
||||
format: {
|
||||
__one_of: ['basic_date', 'basic_date_time', 'basic_date_time_no_millis',
|
||||
'basic_ordinal_date', 'basic_ordinal_date_time', 'basic_ordinal_date_time_no_millis',
|
||||
'basic_time', 'basic_time_no_millis', 'basic_t_time', 'basic_t_time_no_millis',
|
||||
'basic_week_date', 'basic_week_date_time', 'basic_week_date_time_no_millis',
|
||||
'date', 'date_hour', 'date_hour_minute', 'date_hour_minute_second', 'date_hour_minute_second_fraction',
|
||||
'date_hour_minute_second_millis', 'date_optional_time', 'date_time', 'date_time_no_millis',
|
||||
'hour', 'hour_minute', 'hour_minute_second', 'hour_minute_second_fraction', 'hour_minute_second_millis',
|
||||
'ordinal_date', 'ordinal_date_time', 'ordinal_date_time_no_millis', 'time', 'time_no_millis',
|
||||
't_time', 't_time_no_millis', 'week_date', 'week_date_time', 'weekDateTimeNoMillis', 'week_year',
|
||||
'weekyearWeek', 'weekyearWeekDay', 'year', 'year_month', 'year_month_day'
|
||||
]
|
||||
},
|
||||
|
||||
fielddata: {
|
||||
filter: {
|
||||
regex: '',
|
||||
frequency: {
|
||||
min: 0.001,
|
||||
max: 0.1,
|
||||
min_segment_size: 500
|
||||
}
|
||||
}
|
||||
},
|
||||
postings_format: {
|
||||
__one_of: ['direct', 'memory', 'pulsing', 'bloom_default', 'bloom_pulsing', 'default']
|
||||
},
|
||||
similarity: {
|
||||
__one_of: ['default', 'BM25']
|
||||
},
|
||||
|
||||
// objects
|
||||
properties: {
|
||||
__scope_link: '_mapping.$TYPE$.properties'
|
||||
},
|
||||
|
||||
// multi_field
|
||||
path: {
|
||||
__one_of: ['just_name', 'full']
|
||||
},
|
||||
fields: {
|
||||
'*': {
|
||||
__scope_link: '_mapping.$TYPE$.properties.$FIELD$'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
32
sense/app/kb/api_1_0/misc.js
Normal file
32
sense/app/kb/api_1_0/misc.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(api) {
|
||||
api.addEndpointDescription('_stats', {
|
||||
methods: ['GET'],
|
||||
endpoint_autocomplete: ['_stats'],
|
||||
indices_mode: 'multi',
|
||||
types_mode: 'none',
|
||||
doc_id_mode: 'none'
|
||||
});
|
||||
|
||||
api.addEndpointDescription('_cache/clear', {
|
||||
methods: ['GET'],
|
||||
endpoint_autocomplete: ['_cache/clear'],
|
||||
indices_mode: 'multi',
|
||||
types_mode: 'none',
|
||||
doc_id_mode: 'none'
|
||||
});
|
||||
|
||||
api.addEndpointDescription('_status', {
|
||||
methods: ['GET'],
|
||||
indices_mode: 'multi',
|
||||
types_mode: 'none',
|
||||
doc_id_mode: 'none',
|
||||
endpoint_autocomplete: ['_status']
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
});
|
503
sense/app/kb/api_1_0/query.js
Normal file
503
sense/app/kb/api_1_0/query.js
Normal file
|
@ -0,0 +1,503 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
var SPAN_QUERIES = {
|
||||
// TODO add one_of for objects
|
||||
span_first: {
|
||||
__scope_link: '.query.span_first'
|
||||
},
|
||||
span_near: {
|
||||
__scope_link: '.query.span_near'
|
||||
},
|
||||
span_or: {
|
||||
__scope_link: '.query.span_or'
|
||||
},
|
||||
span_not: {
|
||||
__scope_link: '.query.span_not'
|
||||
},
|
||||
span_term: {
|
||||
__scope_link: '.query.span_term'
|
||||
}
|
||||
};
|
||||
|
||||
return function init(api) {
|
||||
api.addGlobalAutocompleteRules('query', {
|
||||
match: {
|
||||
__template: {
|
||||
'FIELD': 'TEXT'
|
||||
},
|
||||
'$FIELD$': {
|
||||
'query': '',
|
||||
'operator': {
|
||||
__one_of: ['and', 'or']
|
||||
},
|
||||
'type': {
|
||||
__one_of: ['phrase', 'phrase_prefix', 'boolean']
|
||||
},
|
||||
'max_expansions': 10,
|
||||
'analyzer': '',
|
||||
'fuzziness': 1.0,
|
||||
'prefix_length': 1
|
||||
}
|
||||
},
|
||||
match_phrase: {
|
||||
__template: {
|
||||
'FIELD': 'PHRASE'
|
||||
},
|
||||
'$FIELD$': {
|
||||
query: '',
|
||||
analyzer: ''
|
||||
}
|
||||
},
|
||||
match_phrase_prefix: {
|
||||
__template: {
|
||||
'FIELD': 'PREFIX'
|
||||
},
|
||||
'$FIELD$': {
|
||||
query: '',
|
||||
analyzer: '',
|
||||
max_expansions: 10,
|
||||
prefix_length: 1,
|
||||
fuzziness: 0.1
|
||||
}
|
||||
},
|
||||
multi_match: {
|
||||
__template: {
|
||||
'query': '',
|
||||
'fields': []
|
||||
},
|
||||
query: '',
|
||||
fields: ['$FIELD$'],
|
||||
use_dis_max: {
|
||||
__template: true,
|
||||
__one_of: [true, false]
|
||||
},
|
||||
tie_breaker: 0.0
|
||||
},
|
||||
bool: {
|
||||
must: [
|
||||
{
|
||||
__scope_link: 'GLOBAL.query'
|
||||
}
|
||||
],
|
||||
must_not: [
|
||||
{
|
||||
__scope_link: 'GLOBAL.query'
|
||||
}
|
||||
],
|
||||
should: [
|
||||
{
|
||||
__scope_link: 'GLOBAL.query'
|
||||
}
|
||||
],
|
||||
minimum_number_should_match: 1,
|
||||
boost: 1.0
|
||||
},
|
||||
boosting: {
|
||||
positive: {
|
||||
__scope_link: '.query'
|
||||
},
|
||||
negative: {
|
||||
__scope_link: '.query'
|
||||
},
|
||||
negative_boost: 0.2
|
||||
},
|
||||
ids: {
|
||||
type: '',
|
||||
values: []
|
||||
},
|
||||
custom_score: {
|
||||
__template: {
|
||||
query: {},
|
||||
script: ''
|
||||
},
|
||||
query: {},
|
||||
script: '',
|
||||
params: {},
|
||||
lang: 'mvel'
|
||||
},
|
||||
custom_boost_factor: {
|
||||
__template: {
|
||||
query: {},
|
||||
boost_factor: 1.1
|
||||
},
|
||||
query: {},
|
||||
boost_factor: 1.1
|
||||
},
|
||||
constant_score: {
|
||||
__template: {
|
||||
filter: {},
|
||||
boost: 1.2
|
||||
},
|
||||
query: {},
|
||||
filter: {},
|
||||
boost: 1.2
|
||||
},
|
||||
dis_max: {
|
||||
__template: {
|
||||
tie_breaker: 0.7,
|
||||
boost: 1.2,
|
||||
queries: []
|
||||
},
|
||||
tie_breaker: 0.7,
|
||||
boost: 1.2,
|
||||
queries: [
|
||||
{
|
||||
__scope_link: '.query'
|
||||
}
|
||||
]
|
||||
},
|
||||
field: {
|
||||
'$FIELD$': {
|
||||
query: '',
|
||||
boost: 2.0,
|
||||
enable_position_increments: {
|
||||
__template: false,
|
||||
__one_of: [true, false]
|
||||
}
|
||||
}
|
||||
},
|
||||
filtered: {
|
||||
__template: {
|
||||
query: {},
|
||||
filter: {}
|
||||
},
|
||||
query: {},
|
||||
filter: {}
|
||||
},
|
||||
fuzzy_like_this: {
|
||||
fields: [],
|
||||
like_text: '',
|
||||
max_query_terms: 12
|
||||
},
|
||||
flt: {
|
||||
__scope_link: '.query.fuzzy_like_this'
|
||||
},
|
||||
fuzzy: {
|
||||
'$FIELD$': {
|
||||
'value': '',
|
||||
'boost': 1.0,
|
||||
'min_similarity': 0.5,
|
||||
'prefix_length': 0
|
||||
}
|
||||
},
|
||||
has_child: {
|
||||
'type': '$TYPE$',
|
||||
'score_type': {
|
||||
__one_of: ['none', 'max', 'sum', 'avg']
|
||||
},
|
||||
'_scope': '',
|
||||
'query': {}
|
||||
},
|
||||
has_parent: {
|
||||
'parent_type': '$TYPE$',
|
||||
'score_type': {
|
||||
__one_of: ['none', 'score']
|
||||
},
|
||||
'_scope': '',
|
||||
'query': {}
|
||||
},
|
||||
match_all: {},
|
||||
more_like_this: {
|
||||
__template: {
|
||||
'fields': ['FIELD'],
|
||||
'like_text': 'text like this one',
|
||||
'min_term_freq': 1,
|
||||
'max_query_terms': 12
|
||||
},
|
||||
fields: ['$FIELD$ '],
|
||||
like_text: '',
|
||||
percent_terms_to_match: 0.3,
|
||||
min_term_freq: 2,
|
||||
max_query_terms: 25,
|
||||
stop_words: [''],
|
||||
min_doc_freq: 5,
|
||||
max_doc_freq: 100,
|
||||
min_word_len: 0,
|
||||
max_word_len: 0,
|
||||
boost_terms: 1,
|
||||
boost: 1.0,
|
||||
analyzer: ''
|
||||
},
|
||||
more_like_this_field: {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
'like_text': 'text like this one',
|
||||
'min_term_freq': 1,
|
||||
'max_query_terms': 12
|
||||
}
|
||||
},
|
||||
'$FIELD$': {
|
||||
like_text: '',
|
||||
percent_terms_to_match: 0.3,
|
||||
min_term_freq: 2,
|
||||
max_query_terms: 25,
|
||||
stop_words: [''],
|
||||
min_doc_freq: 5,
|
||||
max_doc_freq: 100,
|
||||
min_word_len: 0,
|
||||
max_word_len: 0,
|
||||
boost_terms: 1,
|
||||
boost: 1.0,
|
||||
analyzer: ''
|
||||
}
|
||||
},
|
||||
prefix: {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
'value': ''
|
||||
}
|
||||
},
|
||||
'$FIELD$': {
|
||||
value: '',
|
||||
boost: 1.0
|
||||
}
|
||||
},
|
||||
query_string: {
|
||||
__template: {
|
||||
'default_field': 'FIELD',
|
||||
'query': 'this AND that OR thus'
|
||||
},
|
||||
query: '',
|
||||
default_field: '$FIELD$',
|
||||
fields: ['$FIELD$'],
|
||||
default_operator: {
|
||||
__one_of: ['OR', 'AND']
|
||||
},
|
||||
analyzer: '',
|
||||
allow_leading_wildcard: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
lowercase_expanded_terms: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
enable_position_increments: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
fuzzy_max_expansions: 50,
|
||||
fuzzy_min_sim: 0.5,
|
||||
fuzzy_prefix_length: 0,
|
||||
phrase_slop: 0,
|
||||
boost: 1.0,
|
||||
analyze_wildcard: {
|
||||
__one_of: [false, true]
|
||||
},
|
||||
auto_generate_phrase_queries: {
|
||||
__one_of: [false, true]
|
||||
},
|
||||
minimum_should_match: '20%',
|
||||
lenient: {
|
||||
__one_of: [false, true]
|
||||
},
|
||||
use_dis_max: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
tie_breaker: 0
|
||||
},
|
||||
range: {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
from: 10,
|
||||
to: 20
|
||||
}
|
||||
},
|
||||
'$FIELD$': {
|
||||
__template: {
|
||||
from: 10,
|
||||
to: 20
|
||||
},
|
||||
from: 1,
|
||||
to: 20,
|
||||
include_lower: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
include_upper: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
boost: 1.0
|
||||
}
|
||||
},
|
||||
span_first: {
|
||||
__template: {
|
||||
'match': {
|
||||
'span_term': {
|
||||
'FIELD': 'VALUE'
|
||||
}
|
||||
},
|
||||
'end': 3
|
||||
},
|
||||
match: SPAN_QUERIES
|
||||
},
|
||||
span_near: {
|
||||
__template: {
|
||||
'clauses': [
|
||||
{
|
||||
span_term: {
|
||||
'FIELD': {
|
||||
'value': 'VALUE'
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
slop: 12,
|
||||
in_order: false
|
||||
},
|
||||
clauses: [
|
||||
SPAN_QUERIES
|
||||
],
|
||||
slop: 12,
|
||||
in_order: {
|
||||
__one_of: [false, true]
|
||||
},
|
||||
collect_payloads: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
},
|
||||
span_term: {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
'value': 'VALUE'
|
||||
}
|
||||
},
|
||||
'$FIELD$': {
|
||||
value: '',
|
||||
boost: 2.0
|
||||
}
|
||||
},
|
||||
span_not: {
|
||||
__template: {
|
||||
include: {
|
||||
span_term: {
|
||||
'FIELD': {
|
||||
'value': 'VALUE'
|
||||
}
|
||||
}
|
||||
},
|
||||
exclude: {
|
||||
span_term: {
|
||||
'FIELD': {
|
||||
'value': 'VALUE'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
include: SPAN_QUERIES,
|
||||
exclude: SPAN_QUERIES
|
||||
},
|
||||
span_or: {
|
||||
__template: {
|
||||
clauses: [
|
||||
{
|
||||
span_term: {
|
||||
'FIELD': {
|
||||
'value': 'VALUE'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
clauses: [
|
||||
SPAN_QUERIES
|
||||
]
|
||||
},
|
||||
term: {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
value: 'VALUE'
|
||||
}
|
||||
},
|
||||
'$FIELD$': {
|
||||
value: '',
|
||||
boost: 2.0
|
||||
}
|
||||
},
|
||||
terms: {
|
||||
__template: {
|
||||
'FIELD': ['VALUE1', 'VALUE2']
|
||||
},
|
||||
'$FIELD$': [''],
|
||||
minimum_match: 1
|
||||
},
|
||||
top_children: {
|
||||
__template: {
|
||||
type: 'CHILD_TYPE',
|
||||
query: {}
|
||||
},
|
||||
type: '$CHILD_TYPE$',
|
||||
query: {},
|
||||
score: {
|
||||
__one_of: ['max', 'sum', 'avg']
|
||||
},
|
||||
factor: 5,
|
||||
incremental_factor: 2
|
||||
},
|
||||
wildcard: {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
value: 'VALUE'
|
||||
}
|
||||
},
|
||||
'$FIELD$': {
|
||||
value: '',
|
||||
boost: 2.0
|
||||
}
|
||||
},
|
||||
nested: {
|
||||
__template: {
|
||||
path: 'path_to_nested_doc',
|
||||
query: {}
|
||||
},
|
||||
path: '',
|
||||
query: {},
|
||||
filter: {},
|
||||
score_mode: {
|
||||
__one_of: ['avg', 'total', 'max', 'none']
|
||||
}
|
||||
},
|
||||
custom_filters_score: {
|
||||
__template: {
|
||||
query: {},
|
||||
filters: [
|
||||
{
|
||||
filter: {}
|
||||
}
|
||||
]
|
||||
},
|
||||
query: {},
|
||||
filters: [
|
||||
{
|
||||
filter: {},
|
||||
boost: 2.0,
|
||||
script: ''
|
||||
}
|
||||
],
|
||||
score_mode: {
|
||||
__one_of: ['first', 'min', 'max', 'total', 'avg', 'multiply']
|
||||
},
|
||||
max_boost: 2.0,
|
||||
params: {},
|
||||
lang: ''
|
||||
},
|
||||
indices: {
|
||||
__template: {
|
||||
indices: ['INDEX1', 'INDEX2'],
|
||||
query: {}
|
||||
},
|
||||
indices: ['$INDEX$'],
|
||||
query: {},
|
||||
no_match_query: {
|
||||
__scope_link: '.query'
|
||||
}
|
||||
},
|
||||
geo_shape: {
|
||||
__template: {
|
||||
location: {},
|
||||
relation: 'within'
|
||||
},
|
||||
__scope_link: '.filter.geo_shape'
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
});
|
88
sense/app/kb/api_1_0/search.js
Normal file
88
sense/app/kb/api_1_0/search.js
Normal file
|
@ -0,0 +1,88 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(api) {
|
||||
api.addEndpointDescription('_search', {
|
||||
def_method: 'POST',
|
||||
methods: ['GET', 'POST'],
|
||||
endpoint_autocomplete: [
|
||||
'_search'
|
||||
],
|
||||
indices_mode: 'multi',
|
||||
types_mode: 'multi',
|
||||
doc_id_mode: 'none',
|
||||
data_autocomplete_rules: {
|
||||
query: {
|
||||
// populated by a global rule
|
||||
},
|
||||
facets: {
|
||||
__template: {
|
||||
'NAME': {
|
||||
'TYPE': {}
|
||||
}
|
||||
}
|
||||
// populated by a global rule
|
||||
},
|
||||
filter: {
|
||||
// added by global rules.
|
||||
},
|
||||
size: {
|
||||
__template: 20
|
||||
},
|
||||
from: {},
|
||||
sort: {
|
||||
__template: [
|
||||
{
|
||||
'FIELD': {
|
||||
'order': 'desc'
|
||||
}
|
||||
}
|
||||
],
|
||||
__any_of: [
|
||||
{
|
||||
'$FIELD$': {
|
||||
'order': {
|
||||
__one_of: ['desc', 'asc']
|
||||
}
|
||||
}
|
||||
},
|
||||
'$FIELD$',
|
||||
'_score'
|
||||
]
|
||||
},
|
||||
search_type: {},
|
||||
fields: ['$FIELD$'],
|
||||
script_fields: {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
'script': ''
|
||||
}
|
||||
},
|
||||
'*': {
|
||||
__scope_link: 'GLOBAL.SCRIPT_ENV'
|
||||
}
|
||||
},
|
||||
partial_fields: {
|
||||
__template: {
|
||||
'NAME': {
|
||||
include: []
|
||||
}
|
||||
},
|
||||
'*': {
|
||||
include: [],
|
||||
exclude: []
|
||||
}
|
||||
},
|
||||
highlight: {
|
||||
// populated by a global rule
|
||||
},
|
||||
explain: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
stats: ['']
|
||||
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
72
sense/app/kb/api_1_0/settings.js
Normal file
72
sense/app/kb/api_1_0/settings.js
Normal file
|
@ -0,0 +1,72 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(api) {
|
||||
api.addEndpointDescription('_settings', {
|
||||
match: /_settings/,
|
||||
methods: ['GET', 'PUT'],
|
||||
endpoint_autocomplete: ['_settings'],
|
||||
indices_mode: 'multi',
|
||||
types_mode: 'none',
|
||||
doc_id_mode: 'none',
|
||||
data_autocomplete_rules: {
|
||||
index: {
|
||||
refresh_interval: '1s',
|
||||
number_of_shards: 5,
|
||||
number_of_replicas: 1,
|
||||
'blocks.read_only': {
|
||||
__one_of: [false, true]
|
||||
},
|
||||
'blocks.read': {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
'blocks.write': {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
'blocks.metadata': {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
term_index_interval: 32,
|
||||
term_index_divisor: 1,
|
||||
'translog.flush_threshold_ops': 5000,
|
||||
'translog.flush_threshold_size': '200mb',
|
||||
'translog.flush_threshold_period': '30m',
|
||||
'translog.disable_flush': {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
'cache.filter.max_size': '2gb',
|
||||
'cache.filter.expire': '2h',
|
||||
'gateway.snapshot_interval': '10s',
|
||||
routing: {
|
||||
allocation: {
|
||||
include: {
|
||||
tag: ''
|
||||
},
|
||||
exclude: {
|
||||
tag: ''
|
||||
},
|
||||
require: {
|
||||
tag: ''
|
||||
},
|
||||
total_shards_per_node: -1
|
||||
}
|
||||
},
|
||||
'recovery.initial_shards': {
|
||||
__one_of: ['quorum', 'quorum-1', 'half', 'full', 'full-1']
|
||||
},
|
||||
'ttl.disable_purge': {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
analysis: {
|
||||
analyzer: {},
|
||||
tokenizer: {},
|
||||
filter: {},
|
||||
char_filter: {}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
24
sense/app/kb/api_1_0/templates.js
Normal file
24
sense/app/kb/api_1_0/templates.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(api) {
|
||||
api.addEndpointDescription('_template', {
|
||||
match: /\/?_template/,
|
||||
def_method: 'PUT',
|
||||
methods: ['GET', 'PUT', 'DELETE'],
|
||||
endpoint_autocomplete: [
|
||||
'_template/TEMPLATE_ID'
|
||||
],
|
||||
indices_mode: 'none',
|
||||
types_mode: 'none',
|
||||
doc_id_mode: 'none',
|
||||
data_autocomplete_rules: {
|
||||
template: 'index*',
|
||||
warmers: { __scope_link: '_warmer' },
|
||||
mappings: {},
|
||||
settings: {}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
26
sense/app/kb/api_1_0/warmers.js
Normal file
26
sense/app/kb/api_1_0/warmers.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(api) {
|
||||
api.addEndpointDescription('_warmer', {
|
||||
match: /_warmer/,
|
||||
def_method: 'PUT',
|
||||
methods: ['GET', 'PUT', 'DELETE'],
|
||||
endpoint_autocomplete: [
|
||||
'_warmer', '_warmer/WARMER_ID'
|
||||
],
|
||||
indices_mode: 'required_multi',
|
||||
types_mode: 'none',
|
||||
doc_id_mode: 'none',
|
||||
data_autocomplete_rules: {
|
||||
query: {
|
||||
// populated by a global rule
|
||||
},
|
||||
facets: {
|
||||
// populated by a global rule
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
|
@ -1,11 +1,11 @@
|
|||
define([
|
||||
'jquery',
|
||||
'utils',
|
||||
'es',
|
||||
'_'
|
||||
], function ($, utils, _) {
|
||||
], function ($, utils, es, _) {
|
||||
'use strict';
|
||||
|
||||
var currentServer;
|
||||
var per_index_types = {};
|
||||
var per_alias_indexes = [];
|
||||
|
||||
|
@ -197,24 +197,15 @@ define([
|
|||
}
|
||||
|
||||
function retrieveMappingFromServer() {
|
||||
if (!currentServer) return;
|
||||
utils.callES(currentServer, "_mapping", "GET", null, function (data, status, xhr) {
|
||||
es.send("GET", "_mapping", null, function (data, status, xhr) {
|
||||
loadMappings(data);
|
||||
});
|
||||
utils.callES(currentServer, "_aliases", "GET", null, function (data, status, xhr) {
|
||||
es.send("GET", "_aliases", null, function (data, status, xhr) {
|
||||
loadAliases(data);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function notifyServerChange(newServer) {
|
||||
if (newServer.indexOf("://") < 0) newServer = "http://" + newServer;
|
||||
newServer = newServer.trim("/");
|
||||
if (newServer === currentServer) return; // already have it.
|
||||
currentServer = newServer;
|
||||
retrieveMappingFromServer();
|
||||
}
|
||||
|
||||
function mapping_retriever() {
|
||||
retrieveMappingFromServer();
|
||||
setTimeout(function () {
|
||||
|
@ -222,7 +213,11 @@ define([
|
|||
}, 60000);
|
||||
}
|
||||
|
||||
mapping_retriever();
|
||||
es.addServerChangeListener(retrieveMappingFromServer);
|
||||
|
||||
function onInitComplete() {
|
||||
mapping_retriever();
|
||||
}
|
||||
|
||||
return {
|
||||
getFields: getFields,
|
||||
|
@ -232,7 +227,7 @@ define([
|
|||
loadAliases: loadAliases,
|
||||
expandAliases: expandAliases,
|
||||
clear: clear,
|
||||
notifyServerChange: notifyServerChange
|
||||
onInitComplete: onInitComplete
|
||||
};
|
||||
|
||||
});
|
||||
|
|
|
@ -4,16 +4,16 @@ define([
|
|||
'input',
|
||||
'mappings',
|
||||
'output',
|
||||
|
||||
'es',
|
||||
'bootstrap',
|
||||
'jquery-ui'
|
||||
], function ($, history, input, mappings, output) {
|
||||
], function ($, history, input, mappings, output, es) {
|
||||
'use strict';
|
||||
|
||||
var $esServer = $("#es_server");
|
||||
|
||||
$esServer.blur(function () {
|
||||
mappings.notifyServerChange($esServer.val());
|
||||
es.setBaseUrl($esServer.val());
|
||||
});
|
||||
|
||||
// initialize auto complete
|
||||
|
@ -57,7 +57,7 @@ define([
|
|||
});
|
||||
|
||||
var $resizer = input.$el.siblings('.ui-resizable-e');
|
||||
|
||||
es.setBaseUrl($esServer.val());
|
||||
return {
|
||||
$esServer: $esServer,
|
||||
$send: $send,
|
||||
|
@ -65,4 +65,4 @@ define([
|
|||
$header: $header,
|
||||
$resizer: $resizer
|
||||
};
|
||||
})
|
||||
});
|
|
@ -5,8 +5,9 @@ define([
|
|||
'jquery',
|
||||
'sense_editor/row_parser',
|
||||
'sense_editor/mode/sense',
|
||||
'utils'
|
||||
], function (_, ace, curl, $, RowParser, SenseMode, utils) {
|
||||
'utils',
|
||||
'es'
|
||||
], function (_, ace, curl, $, RowParser, SenseMode, utils, es) {
|
||||
'use strict';
|
||||
|
||||
function isInt(x) {
|
||||
|
@ -79,7 +80,8 @@ define([
|
|||
setTimeout(function check() {
|
||||
if (session.bgTokenizer.running) {
|
||||
timer = setTimeout(check, checkInterval);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
func.apply(self, args);
|
||||
}
|
||||
});
|
||||
|
@ -104,7 +106,9 @@ define([
|
|||
|
||||
editor.autoIndent = onceDoneTokenizing(function () {
|
||||
editor.getCurrentRequestRange(function (req_range) {
|
||||
if (!req_range) return;
|
||||
if (!req_range) {
|
||||
return;
|
||||
}
|
||||
editor.getCurrentRequest(function (parsed_req) {
|
||||
if (parsed_req.data && parsed_req.data.length > 0) {
|
||||
var indent = parsed_req.data.length == 1; // unindent multi docs by default
|
||||
|
@ -160,7 +164,9 @@ define([
|
|||
};
|
||||
|
||||
editor.getCurrentRequestRange = onceDoneTokenizing(function (cb) {
|
||||
if (typeof cb !== 'function') return;
|
||||
if (typeof cb !== 'function') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (editor.parser.isInBetweenRequestsRow(null)) {
|
||||
cb(null);
|
||||
|
@ -176,7 +182,9 @@ define([
|
|||
});
|
||||
|
||||
editor.getCurrentRequest = onceDoneTokenizing(function (cb) {
|
||||
if (typeof cb !== 'function') return;
|
||||
if (typeof cb !== 'function') {
|
||||
return;
|
||||
}
|
||||
if (editor.parser.isInBetweenRequestsRow(null)) {
|
||||
cb(null);
|
||||
return;
|
||||
|
@ -198,7 +206,9 @@ define([
|
|||
}
|
||||
request.method = t.value;
|
||||
t = editor.parser.nextNonEmptyToken(tokenIter);
|
||||
if (!t || t.type == "method") return null;
|
||||
if (!t || t.type == "method") {
|
||||
return null;
|
||||
}
|
||||
request.url = "";
|
||||
while (t && t.type && t.type.indexOf("url") == 0) {
|
||||
request.url += t.value;
|
||||
|
@ -251,8 +261,12 @@ define([
|
|||
var maxLines = session.getLength();
|
||||
for (; curRow < maxLines - 1; curRow++) {
|
||||
var curRowMode = editor.parser.getRowParseMode(curRow, editor);
|
||||
if ((curRowMode & RowParser.MODE_REQUEST_END) > 0) break;
|
||||
if (curRow != pos.row && (curRowMode & RowParser.MODE_REQUEST_START) > 0) break;
|
||||
if ((curRowMode & RowParser.MODE_REQUEST_END) > 0) {
|
||||
break;
|
||||
}
|
||||
if (curRow != pos.row && (curRowMode & RowParser.MODE_REQUEST_START) > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var column = (session.getLine(curRow) || "").length;
|
||||
|
@ -270,8 +284,12 @@ define([
|
|||
if ((curRowMode & RowParser.REQUEST_END) > 0) {
|
||||
break;
|
||||
}
|
||||
if ((curRowMode & RowParser.MODE_MULTI_DOC_CUR_DOC_END) > 0) break;
|
||||
if (curRow != pos.row && (curRowMode & RowParser.MODE_REQUEST_START) > 0) break;
|
||||
if ((curRowMode & RowParser.MODE_MULTI_DOC_CUR_DOC_END) > 0) {
|
||||
break;
|
||||
}
|
||||
if (curRow != pos.row && (curRowMode & RowParser.MODE_REQUEST_START) > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var column = (session.getLine(curRow) || "").length;
|
||||
|
@ -291,9 +309,13 @@ define([
|
|||
|
||||
editor.handleCURLPaste = function (text) {
|
||||
var curlInput = curl.parseCURL(text);
|
||||
if ($("#es_server").val()) curlInput.server = null; // do not override server
|
||||
if ($("#es_server").val()) {
|
||||
curlInput.server = null;
|
||||
} // do not override server
|
||||
|
||||
if (!curlInput.method) curlInput.method = "GET";
|
||||
if (!curlInput.method) {
|
||||
curlInput.method = "GET";
|
||||
}
|
||||
|
||||
editor.insert(utils.textFromRequest(curlInput));
|
||||
};
|
||||
|
@ -301,7 +323,9 @@ define([
|
|||
editor.highlightCurrentRequestAndUpdateActionBar = onceDoneTokenizing(function () {
|
||||
var session = editor.getSession();
|
||||
editor.getCurrentRequestRange(function (new_current_req_range) {
|
||||
if (new_current_req_range == null && CURRENT_REQ_RANGE == null) return;
|
||||
if (new_current_req_range == null && CURRENT_REQ_RANGE == null) {
|
||||
return;
|
||||
}
|
||||
if (new_current_req_range != null && CURRENT_REQ_RANGE != null &&
|
||||
new_current_req_range.start.row == CURRENT_REQ_RANGE.start.row &&
|
||||
new_current_req_range.end.row == CURRENT_REQ_RANGE.end.row
|
||||
|
@ -329,21 +353,25 @@ define([
|
|||
editor.getCurrentRequestAsCURL = function (cb) {
|
||||
cb = typeof cb === 'function' ? cb : $.noop;
|
||||
editor.getCurrentRequest(function (req) {
|
||||
if (!req) return;
|
||||
if (!req) {
|
||||
return;
|
||||
}
|
||||
|
||||
var es_server = $("#es_server").val(),
|
||||
es_url = req.url,
|
||||
var
|
||||
es_path = req.url,
|
||||
es_method = req.method,
|
||||
es_data = req.data;
|
||||
|
||||
var url = utils.constructESUrl(es_server, es_url);
|
||||
var url = es.constructESUrl(es_path);
|
||||
|
||||
var curl = 'curl -X' + es_method + ' "' + url + '"';
|
||||
if (es_data && es_data.length) {
|
||||
curl += " -d'\n";
|
||||
// since Sense doesn't allow single quote json string any single qoute is within a string.
|
||||
curl += es_data.join("\n").replace(/'/g, '\\"');
|
||||
if (es_data.length > 1) curl += "\n"; // end with a new line
|
||||
if (es_data.length > 1) {
|
||||
curl += "\n";
|
||||
} // end with a new line
|
||||
curl += "'";
|
||||
}
|
||||
|
||||
|
@ -363,7 +391,8 @@ define([
|
|||
var set = function (top) {
|
||||
if (top == null) {
|
||||
editor.$actions.css('visibility', 'hidden');
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
editor.$actions.css({
|
||||
top: top,
|
||||
visibility: 'visible'
|
||||
|
|
|
@ -20,7 +20,7 @@ define([
|
|||
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
|
||||
};
|
||||
|
||||
utils.jsonToString = function(data, indent) {
|
||||
utils.jsonToString = function (data, indent) {
|
||||
return JSON.stringify(data, null, indent ? 2 : 0);
|
||||
};
|
||||
|
||||
|
@ -46,41 +46,6 @@ define([
|
|||
};
|
||||
};
|
||||
|
||||
utils.callES = function (server, url, method, data, successCallback, completeCallback) {
|
||||
url = utils.constructESUrl(server, url);
|
||||
var uname_password_re = /^(https?:\/\/)?(?:(?:([^\/]*):)?([^\/]*?)@)?(.*)$/;
|
||||
var url_parts = url.match(uname_password_re);
|
||||
|
||||
var uname = url_parts[2];
|
||||
var password = url_parts[3];
|
||||
url = url_parts[1] + url_parts[4];
|
||||
console.log("Calling " + url + " (uname: " + uname + " pwd: " + password + ")");
|
||||
if (data && method == "GET") method = "POST";
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
data: method == "GET" ? null : data,
|
||||
password: password,
|
||||
cache: false,
|
||||
username: uname,
|
||||
crossDomain: true,
|
||||
type: method,
|
||||
dataType: "json",
|
||||
complete: completeCallback,
|
||||
success: successCallback
|
||||
});
|
||||
};
|
||||
|
||||
utils.constructESUrl = function (server, url) {
|
||||
if (url.indexOf("://") >= 0) return url;
|
||||
if (server.indexOf("://") < 0) server = "http://" + server;
|
||||
if (server.substr(-1) == "/") {
|
||||
server = server.substr(0, server.length - 1);
|
||||
}
|
||||
if (url.charAt(0) === "/") url = url.substr(1);
|
||||
|
||||
return server + "/" + url;
|
||||
};
|
||||
|
||||
return utils;
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue