mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Support fields from nested objects pulled from Elasticsearch
This commit is contained in:
@@ -86,7 +86,23 @@ function (angular, _, config, kbn, moment) {
|
||||
var list = [];
|
||||
var hits = results.data.hits.hits;
|
||||
|
||||
var getFieldFromSource = function(source, fieldName) {
|
||||
var fieldValue;
|
||||
if (fieldName) {
|
||||
var fieldNames = fieldName.split('.');
|
||||
fieldValue = source;
|
||||
for (var i = 0; i < fieldNames.length; i++) {
|
||||
fieldValue = fieldValue[fieldNames[i]];
|
||||
}
|
||||
if (_.isArray(fieldValue)) {
|
||||
fieldValue = fieldValue.join(',');
|
||||
}
|
||||
}
|
||||
return fieldValue;
|
||||
};
|
||||
|
||||
for (var i = 0; i < hits.length; i++) {
|
||||
console.log('annotationQuery', hits[i]);
|
||||
var source = hits[i]._source;
|
||||
var fields = hits[i].fields;
|
||||
var time = source[timeField];
|
||||
@@ -98,21 +114,11 @@ function (angular, _, config, kbn, moment) {
|
||||
var event = {
|
||||
annotation: annotation,
|
||||
time: moment.utc(time).valueOf(),
|
||||
title: source[titleField],
|
||||
title: getFieldFromSource(source, titleField),
|
||||
tags: getFieldFromSource(source, tagsField),
|
||||
text: getFieldFromSource(source, textField)
|
||||
};
|
||||
|
||||
if (source[tagsField]) {
|
||||
if (_.isArray(source[tagsField])) {
|
||||
event.tags = source[tagsField].join(', ');
|
||||
}
|
||||
else {
|
||||
event.tags = source[tagsField];
|
||||
}
|
||||
}
|
||||
if (textField && source[textField]) {
|
||||
event.text = source[textField];
|
||||
}
|
||||
|
||||
list.push(event);
|
||||
}
|
||||
return list;
|
||||
|
||||
Reference in New Issue
Block a user