visualise-elastic-profile
Version:
Visualise results from Profile API of ElasticSearch on the command line
48 lines • 1.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAllLeafQueriesFromProfile = exports.getQueryTypesFromProfile = exports.arrayToMultiMap = void 0;
function arrayToMultiMap(items, keyFunction, valueFunction = (item) => item) {
return items.reduce((map, item) => {
const key = keyFunction(item);
let values = map.get(key);
if (values === undefined) {
values = [];
map.set(key, values);
}
values.push(valueFunction(item));
return map;
}, new Map());
}
exports.arrayToMultiMap = arrayToMultiMap;
function getQueryTypesFromProfile(profile) {
function getAllQueryTypes(query, aggregator) {
aggregator.add(query.type);
if (query.children !== undefined) {
for (const child of query.children) {
getAllQueryTypes(child, aggregator);
}
}
}
const queryTypes = new Set();
const topLevelQueries = profile.shards.flatMap((shard) => shard.searches).flatMap((search) => search.query);
for (const query of topLevelQueries) {
getAllQueryTypes(query, queryTypes);
}
return queryTypes;
}
exports.getQueryTypesFromProfile = getQueryTypesFromProfile;
function getAllLeafQueriesFromProfile(profile) {
function getAllLeafQueries(query) {
const children = query.children;
if (children === undefined) {
return [query];
}
return children.flatMap((child) => getAllLeafQueries(child));
}
return profile.shards
.flatMap((shard) => shard.searches)
.flatMap((search) => search.query)
.flatMap((query) => getAllLeafQueries(query));
}
exports.getAllLeafQueriesFromProfile = getAllLeafQueriesFromProfile;
//# sourceMappingURL=utils.js.map