Skip to content

Commit

Permalink
Update CustomESResponseSerializer.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
ksuess committed May 17, 2021
1 parent ad17506 commit 1a3f2e2
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/components/Searchkit/CustomESResponseSerializer.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
// TODO add data of .title to serialized response
// aggregations.organisationunit_agg.organisationunit_token.buckets[1].somemoredatafromelasticsearch.hits.hits[0]._source.title

import { forEach, has } from 'lodash';

function _pimpedAggregations(aggregations) {
let result = Object.assign({}, aggregations);
let buckets = [];
Object.keys(aggregations).forEach((element) => {
Object.keys(aggregations[element]).forEach((token) => {
if (token !== 'doc_count') {
buckets = aggregations[element][token].buckets;
buckets &&
buckets.forEach((bucket) => {
bucket.label =
bucket.somemoredatafromelasticsearch.hits.hits[0]._source.title;
});
}
});
Object.keys(result).forEach((element) => {
if (result[element].buckets) {
buckets = result[element].buckets;
} else {
forEach(result[element].inner, function (value, key) {
if (has(value, 'buckets')) {
buckets = result[element].inner[key].buckets;
}
});
}
buckets &&
buckets.forEach((bucket) => {
bucket.label =
bucket.somemoredatafromelasticsearch?.hits.hits[0]._source.title ??
bucket.key;
});
});

return result;
Expand Down

0 comments on commit 1a3f2e2

Please sign in to comment.