Skip to content

Commit

Permalink
update API calls to be OpenSearch compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
k-rister committed Jan 26, 2024
1 parent 5287bb5 commit 41d7863
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions queries/cdmq/cdm.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ mSearch = function (url, index, termKeys, values, source, aggs, size, sort) {
}
ndjson += '{}\n' + JSON.stringify(req) + '\n';
}
var resp = esRequest(url, index + '/_doc/_msearch', ndjson);
var resp = esRequest(url, index + '/_msearch', ndjson);
var data = JSON.parse(resp.getBody());

// Unpack response and organize in array of arrays
Expand Down Expand Up @@ -638,7 +638,7 @@ getIterMetrics = function (url, iterId) {
deleteDocs = function (url, docTypes, q) {
docTypes.forEach((docType) => {
//console.log("deleteDocs() query:\n" + JSON.stringify(q, null, 2));
var resp = esRequest(url, docType + '/_doc/_delete_by_query', q);
var resp = esRequest(url, docType + '/_delete_by_query', q);
var data = JSON.parse(resp.getBody());
});
};
Expand Down Expand Up @@ -1063,7 +1063,7 @@ getIters = function (
});

if (ndjson != '') {
var resp = esRequest(url, 'tag/_doc/_msearch', ndjson);
var resp = esRequest(url, 'tag/_msearch', ndjson);
var data = JSON.parse(resp.getBody());
var runIds = [];
data.responses.forEach((response) => {
Expand All @@ -1076,7 +1076,7 @@ getIters = function (
var intersectedRunIds = intersectAllArrays(runIds);

if (ndjson2 != '') {
var resp2 = esRequest(url, 'tag/_doc/_msearch', ndjson2);
var resp2 = esRequest(url, 'tag/_msearch', ndjson2);
var data2 = JSON.parse(resp2.getBody());
data2.responses.forEach((response) => {
response.hits.hits.forEach((run) => {
Expand Down Expand Up @@ -1129,7 +1129,7 @@ getIters = function (

var iterIdsFromParam = [];
if (ndjson != '') {
var resp = esRequest(url, 'param/_doc/_msearch', ndjson);
var resp = esRequest(url, 'param/_msearch', ndjson);
var data = JSON.parse(resp.getBody());
var iterationIds = [];
data.responses.forEach((response) => {
Expand All @@ -1142,7 +1142,7 @@ getIters = function (
iterIdsFromParam = intersectAllArrays(iterationIds);

if (ndjson2 != '') {
var resp2 = esRequest(url, 'tag/_doc/_msearch', ndjson2);
var resp2 = esRequest(url, 'tag/_msearch', ndjson2);
var data2 = JSON.parse(resp2.getBody());
data2.responses.forEach((response) => {
response.hits.hits.forEach((hit) => {
Expand Down Expand Up @@ -1443,7 +1443,7 @@ exports.getMetricSources = function (url, runId) {
size: 0
};
//console.log("Q:\n" + JSON.stringify(q, null, 2));
var resp = esRequest(url, 'metric_desc/_doc/_search', q);
var resp = esRequest(url, 'metric_desc/_search', q);
var data = JSON.parse(resp.getBody());
if (Array.isArray(data.aggregations.source.buckets)) {
var sources = [];
Expand All @@ -1456,7 +1456,7 @@ exports.getMetricSources = function (url, runId) {

exports.getDocCount = function (url, runId, docType) {
var q = { query: { bool: { filter: [{ term: { 'run.id': runId } }] } } };
var resp = esRequest(url, docType + '/_doc/_count', q);
var resp = esRequest(url, docType + '/_count', q);
var data = JSON.parse(resp.getBody());
return data.count;
};
Expand Down Expand Up @@ -1595,7 +1595,7 @@ mgetMetricIdsFromTerms = function (url, termsSets) {
});
}
//console.log("mgetMetricIdsFromTerms(): ndjson:\n" + ndjson + "\n");
var resp = esRequest(url, 'metric_desc/_doc/_msearch', ndjson);
var resp = esRequest(url, 'metric_desc/_msearch', ndjson);
var data = JSON.parse(resp.getBody());
if (totalReqs != data.responses.length) {
console.log('mgetMetricIdsFromTerms(): ERROR, number of _msearch responses did not match number of requests');
Expand Down Expand Up @@ -1701,7 +1701,7 @@ getMetricGroupsFromBreakouts = function (url, sets) {
ndjson += JSON.stringify(index) + '\n';
ndjson += JSON.stringify(q) + '\n';
});
var resp = esRequest(url, 'metric_desc/_doc/_msearch', ndjson);
var resp = esRequest(url, 'metric_desc/_msearch', ndjson);
var data = JSON.parse(resp.getBody());

var metricGroupIdsByLabelSets = [];
Expand Down Expand Up @@ -1895,7 +1895,7 @@ getMetricDataFromIdsSets = function (url, sets, metricGroupIdsByLabelSets) {
});
}

var resp = esRequest(url, 'metric_data/_doc/_msearch', ndjson);
var resp = esRequest(url, 'metric_data/_msearch', ndjson);
var data = JSON.parse(resp.getBody());
var elements = data.responses.length;

Expand Down

0 comments on commit 41d7863

Please sign in to comment.