From 63f6e86e46fa334342037c5cde2a6d0b69336295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 6 Jan 2017 06:35:08 +0100 Subject: [PATCH] feat(ES): better support for text type, closes #7151 --- .../datasource/elasticsearch/datasource.js | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/datasource.js b/public/app/plugins/datasource/elasticsearch/datasource.js index 3a3e81a1f74..38fd6337f22 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.js +++ b/public/app/plugins/datasource/elasticsearch/datasource.js @@ -231,6 +231,7 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes this.getFields = function(query) { return this._get('/_mapping').then(function(result) { + var typeMap = { 'float': 'number', 'double': 'number', @@ -238,14 +239,28 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes 'long': 'number', 'date': 'date', 'string': 'string', - 'text': 'text', + 'text': 'string', 'scaled_float': 'number', '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 var fieldNameParts = []; var fields = {}; + function getFieldsRecursively(obj) { for (var key in obj) { var subObj = obj[key]; @@ -258,10 +273,7 @@ function (angular, _, moment, kbn, ElasticQueryBuilder, IndexPattern, ElasticRes var fieldName = fieldNameParts.concat(key).join('.'); // Hide meta-fields and check field type - if (key[0] !== '_' && - (!query.type || - query.type && typeMap[subObj.type] === query.type)) { - + if (shouldAddField(subObj, key, query)) { fields[fieldName] = { text: fieldName, type: subObj.type