mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Expose field type as meta in autocomplete
This commit is contained in:
parent
fbf8b289c1
commit
f2b2fa9db7
3 changed files with 56 additions and 29 deletions
|
@ -752,7 +752,9 @@ define([
|
|||
return addMetaToTermsList(mappings.getTypes(activeScheme.indices), "type");
|
||||
}
|
||||
else if (term == "$FIELD$") {
|
||||
return addMetaToTermsList(mappings.getFields(activeScheme.indices, activeScheme.types), "field");
|
||||
return _.map(mappings.getFields(activeScheme.indices, activeScheme.types), function (f) {
|
||||
return { name: f.name, meta: f.type };
|
||||
});
|
||||
}
|
||||
return [ term ]
|
||||
}
|
||||
|
@ -849,8 +851,11 @@ define([
|
|||
addMetaToTermsList(mappings.getTypes(activeScheme.indices), "type", template_for_term));
|
||||
break;
|
||||
case "$FIELD$":
|
||||
/* jshint -W083 */
|
||||
$.merge(autocompleteSet,
|
||||
addMetaToTermsList(mappings.getFields(activeScheme.indices, activeScheme.types), "field", template_for_term));
|
||||
_.map(mappings.getFields(activeScheme.indices, activeScheme.types), function (f) {
|
||||
return { name: f.name, meta: f.type, template: template_for_term };
|
||||
}));
|
||||
break;
|
||||
default:
|
||||
autocompleteSet.push({ name: term, template: template_for_term });
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
define([
|
||||
'jquery',
|
||||
'utils'
|
||||
], function ($, utils) {
|
||||
'utils',
|
||||
'_'
|
||||
], function ($, utils, _) {
|
||||
'use strict';
|
||||
|
||||
var currentServer;
|
||||
|
@ -62,7 +63,9 @@ define([
|
|||
ret = [].concat.apply([], ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return _.uniq(ret, function (f) {
|
||||
return f.name + ":" + f.type
|
||||
});
|
||||
}
|
||||
|
||||
function getTypes(indices) {
|
||||
|
@ -87,9 +90,7 @@ define([
|
|||
ret = [].concat.apply([], ret);
|
||||
}
|
||||
|
||||
return ret.filter(function (v, i, a) {
|
||||
return a.indexOf(v) == i
|
||||
}); // dedupe array;
|
||||
return _.uniq(ret);
|
||||
|
||||
}
|
||||
|
||||
|
@ -115,7 +116,8 @@ define([
|
|||
var path_type = field_mapping['path'] || "full";
|
||||
if (path_type == "full") {
|
||||
return $.map(nested_field_names, function (f) {
|
||||
return field_name + "." + f;
|
||||
f.name = field_name + "." + f.name;
|
||||
return f;
|
||||
});
|
||||
}
|
||||
return nested_field_names;
|
||||
|
@ -127,7 +129,9 @@ define([
|
|||
return applyPathSettings(nested_fields);
|
||||
}
|
||||
|
||||
if (field_mapping['type'] == 'multi_field') {
|
||||
var field_type = field_mapping['type'];
|
||||
|
||||
if (field_type === 'multi_field') {
|
||||
nested_fields = $.map(field_mapping['fields'], function (field_mapping, field_name) {
|
||||
return getFieldNamesFromFieldMapping(field_name, field_mapping);
|
||||
});
|
||||
|
@ -135,9 +139,11 @@ define([
|
|||
return applyPathSettings(nested_fields);
|
||||
}
|
||||
|
||||
if (field_mapping["index_name"]) return [field_mapping["index_name"]];
|
||||
var ret = { name: field_name, type: field_type };
|
||||
|
||||
return [field_name];
|
||||
if (field_mapping["index_name"]) ret.name = field_mapping["index_name"];
|
||||
|
||||
return [ret];
|
||||
}
|
||||
|
||||
function getFieldNamesFromTypeMapping(type_mapping) {
|
||||
|
@ -147,12 +153,8 @@ define([
|
|||
});
|
||||
|
||||
// deduping
|
||||
var last;
|
||||
field_list.sort();
|
||||
return $.map(field_list, function (f) {
|
||||
var r = (f === last) ? null : f;
|
||||
last = f;
|
||||
return r;
|
||||
return _.uniq(field_list, function (f) {
|
||||
return f.name + ":" + f.type
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -229,4 +231,4 @@ define([
|
|||
notifyServerChange: notifyServerChange
|
||||
};
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,6 +3,25 @@ define([
|
|||
], function (mappings) {
|
||||
'use strict';
|
||||
|
||||
module("Mappings", {
|
||||
setup: function () {
|
||||
mappings.clear();
|
||||
},
|
||||
teardown: function () {
|
||||
mappings.clear();
|
||||
}
|
||||
});
|
||||
|
||||
function fc(f1, f2) {
|
||||
if (f1.name < f2.name) return -1;
|
||||
if (f1.name > f2.name) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
function f(name, type) {
|
||||
return { name: name, type: type || "string"};
|
||||
}
|
||||
|
||||
test("Multi fields", function () {
|
||||
mappings.loadMappings({
|
||||
"index": {
|
||||
|
@ -29,7 +48,8 @@ define([
|
|||
}
|
||||
});
|
||||
|
||||
deepEqual(mappings.getFields("index").sort(), ["any_name", "first_name", "last_name" ]);
|
||||
deepEqual(mappings.getFields("index").sort(fc), [
|
||||
f("any_name", "string"), f("first_name", "string"), f("last_name", "string")]);
|
||||
});
|
||||
|
||||
test("Simple fields", function () {
|
||||
|
@ -48,7 +68,7 @@ define([
|
|||
}
|
||||
});
|
||||
|
||||
deepEqual(mappings.getFields("index").sort(), ["number", "str" ]);
|
||||
deepEqual(mappings.getFields("index").sort(fc), [f("number", "int"), f("str", "string") ]);
|
||||
});
|
||||
|
||||
|
||||
|
@ -75,8 +95,8 @@ define([
|
|||
}
|
||||
});
|
||||
|
||||
deepEqual(mappings.getFields("index", ["tweet"]).sort(),
|
||||
["message", "person.name.first_name", "person.name.last_name", "person.sid" ]);
|
||||
deepEqual(mappings.getFields("index", ["tweet"]).sort(fc),
|
||||
[f("message"), f("person.name.first_name"), f("person.name.last_name"), f("person.sid")]);
|
||||
});
|
||||
|
||||
test("Enabled fields", function () {
|
||||
|
@ -100,8 +120,8 @@ define([
|
|||
}
|
||||
});
|
||||
|
||||
deepEqual(mappings.getFields("index", ["tweet"]).sort(),
|
||||
["message", "person.sid" ]);
|
||||
deepEqual(mappings.getFields("index", ["tweet"]).sort(fc),
|
||||
[f("message"), f("person.sid") ]);
|
||||
});
|
||||
|
||||
|
||||
|
@ -131,8 +151,8 @@ define([
|
|||
}
|
||||
});
|
||||
|
||||
deepEqual(mappings.getFields().sort(),
|
||||
["first1", "i_last_1", "name2.first2", "name2.i_last_2" ]);
|
||||
deepEqual(mappings.getFields().sort(fc),
|
||||
[f("first1"), f("i_last_1"), f("name2.first2"), f("name2.i_last_2") ]);
|
||||
});
|
||||
|
||||
test("Use index_name tests", function () {
|
||||
|
@ -146,8 +166,8 @@ define([
|
|||
}
|
||||
});
|
||||
|
||||
deepEqual(mappings.getFields().sort(),
|
||||
[ "i_last_1" ]);
|
||||
deepEqual(mappings.getFields().sort(fc),
|
||||
[f("i_last_1")]);
|
||||
});
|
||||
|
||||
test("Aliases", function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue