Commit 63f6e86e by Torkel Ödegaard

feat(ES): better support for text type, closes #7151

parent 658d3994
...@@ -231,6 +231,7 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes ...@@ -231,6 +231,7 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
this.getFields = function(query) { this.getFields = function(query) {
return this._get('/_mapping').then(function(result) { return this._get('/_mapping').then(function(result) {
var typeMap = { var typeMap = {
'float': 'number', 'float': 'number',
'double': 'number', 'double': 'number',
...@@ -238,14 +239,28 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes ...@@ -238,14 +239,28 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
'long': 'number', 'long': 'number',
'date': 'date', 'date': 'date',
'string': 'string', 'string': 'string',
'text': 'text', 'text': 'string',
'scaled_float': 'number', 'scaled_float': 'number',
'nested': 'nested' 'nested': 'nested'
}; };
function shouldAddField(obj, key, query) {
if (key[0] === '_') {
return false;
}
if (!query.type) {
return true;
}
// equal query type filter, or via typemap translation
return query.type === obj.type || query.type === typeMap[obj.type];
}
// Store subfield names: [system, process, cpu, total] -> system.process.cpu.total // Store subfield names: [system, process, cpu, total] -> system.process.cpu.total
var fieldNameParts = []; var fieldNameParts = [];
var fields = {}; var fields = {};
function getFieldsRecursively(obj) { function getFieldsRecursively(obj) {
for (var key in obj) { for (var key in obj) {
var subObj = obj[key]; var subObj = obj[key];
...@@ -258,10 +273,7 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes ...@@ -258,10 +273,7 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes
var fieldName = fieldNameParts.concat(key).join('.'); var fieldName = fieldNameParts.concat(key).join('.');
// Hide meta-fields and check field type // Hide meta-fields and check field type
if (key[0] !== '_' && if (shouldAddField(subObj, key, query)) {
(!query.type ||
query.type && typeMap[subObj.type] === query.type)) {
fields[fieldName] = { fields[fieldName] = {
text: fieldName, text: fieldName,
type: subObj.type type: subObj.type
......
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