Open ErwanPigneul opened 10 years ago
@babeya : if you have any idea about this.
I'm trying to identify the path behind main aggregation but I'm not sure about the way to display user choices. ...
Thanks Arthur, your english is surely better than mine. I'm already working on the second way. I would like to discover the path of data fields behind an aggregation and offer a select method for the user. And pass the paths to datas to the graph.
I'm yet thinking on it. At this time, I just code a recursive method to discover the paths.
I hope your studies are all right.
The problem with the recursive method is when a field is missing in a sub-object of the main aggregation, if you are unlucky, your paths may be good for one bucket, but not for all. That is currently the main issue in aggregation's csv export. I thought a lot about this and the best and proper way to handle this case is to hard code in aggregation.json file, different fields of each aggregation. Then you will be able to built each aggregation's tree quickly.
This is an example of what I was beginning to use : a data field to say where are values a nested field if data are not on the root tree.
{ "list": [{ "type": "Terms", "template": "partials/aggregation_module/settings_partials/terms.html", "resultTemplate": "partials/aggregation/Terms.html", "mapping": { "buckets": ["doc_count", "key"] }, "data": ["doc_count", "key"], "nested": "bucket[0]" }, { "type": "Range", "template": "partials/aggregation_module/settings_partials/range.html", "resultTemplate": "partials/aggregation/default.html", "mapping": { "buckets": ["doc_count", "key"] }, "data": ["doc_count", "key"], "nested": "bucket[0]" }, { "type": "DateRange", "template": "partials/aggregation_module/settings_partials/date_range.html", "resultTemplate": "partials/aggregation/Terms.html", "mapping": { "buckets": ["doc_count", "key"] }, "data": ["doc_count", "key"], "nested": "bucket[0]" }, { "type": "Histogram", "template": "partials/aggregation_module/settings_partials/histogram.html", "resultTemplate": "partials/aggregation/Terms.html", "mapping": { "buckets": ["doc_count", "key"] }, "data": ["doc_count", "key"], "nested": "bucket[0]" }, { "type": "DateHistogram", "template": "partials/aggregation_module/settings_partials/date_histogram.html", "resultTemplate": "partials/aggregation/Terms.html", "mapping": { "buckets": ["doc_count", "key"] }, "data": ["doc_count", "key"], "nested": "bucket[0]" }, { "type": "Avg", "template": "partials/aggregation_module/settings_partials/simple.html", "resultTemplate": "partials/aggregation/default.html", "mapping": { "value": "" }, "data": ["value"] },
...
And a function :+1: /*
* @desc create a path for this agregation and all is nested
* @param object data the table from where wz want to concat
* @param name name of aggregation
/
aggObj.evaluateAllPath = function (agg, prefix, tab) {
var i = 0;
data = []
console.log(agg)
if (typeof(agg.pathToNestedData) === "undefined") {
while (i < agg.pathToData.length) {
// data.push(prefix + agg.pathToData[i]);
tab.push(prefix + agg.pathToData[i]);
i++;
}
} else {
if (agg.pathToNestedData !== '.') {
prefix = prefix + agg.pathToNestedData + '.';
}
// console.log(JSON.stringify(data));
while (i < agg.pathToData.length) {
console.log(agg.pathToData[i])
// data.push(prefix + agg.pathToData[i]);
tab.push(prefix + agg.pathToData[i]);
i++;
}
if (typeof(agg.nested) !== "undefined") {
for (sub_agg in agg.nested) {
// console.log(sub_agg)
if (aggObj.isAgg(sub_agg)) {
//data.concat(aggObj.evaluateAllPath(agg.nested[sub_agg], prefix, tab));
aggObj.evaluateAllPath(agg.nested[sub_agg], prefix + sub_agg + '.' , tab);
// tab.concat(aggObj.evaluateAllPath(agg.nested[sub_agg], prefix, tab));
// console.log(sub_agg + '--->' + prefix)
}
}
}
}
console.log(tab)
// return data
}
If you make for example a dateHistogram and want to count a valus with a sum agg, you need to create a custom agg template wiith tyhe good way to acces values. The idea is to have a way to just declare it without the need to create a custom template.